From 7bd623aeed5792fd89f2cbde71c649b89a90f551 Mon Sep 17 00:00:00 2001 From: richie Date: Fri, 16 Aug 2019 15:03:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A9=BA=E6=A0=87=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fanruan/api/cal/FormulaKit.java | 8 ++-- .../com/fanruan/api/cal/ParameterKit.java | 5 +- .../com/fanruan/api/data/TableDataKit.java | 5 +- .../java/com/fanruan/api/login/LoginKit.java | 46 +++++++++++++++++++ .../java/com/fanruan/api/net/NetworkKit.java | 7 +-- .../com/fanruan/api/session/SessionKit.java | 3 +- .../java/com/fanruan/api/util/GeneralKit.java | 28 ++++++++--- 7 files changed, 84 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/fanruan/api/login/LoginKit.java diff --git a/src/main/java/com/fanruan/api/cal/FormulaKit.java b/src/main/java/com/fanruan/api/cal/FormulaKit.java index 16ac7f1..2cb45fe 100644 --- a/src/main/java/com/fanruan/api/cal/FormulaKit.java +++ b/src/main/java/com/fanruan/api/cal/FormulaKit.java @@ -6,6 +6,8 @@ import com.fr.script.Calculator; import com.fr.stable.FormulaProvider; import com.fr.stable.UtilEvalError; import com.fr.stable.script.CalculatorProvider; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author richie @@ -21,7 +23,7 @@ public class FormulaKit { * @return 公式计算后的结果值 * @throws KitError 如果计算过程中出现错误,则抛出此异常 */ - public static Object eval(String formula) throws KitError { + public static @Nullable Object eval(String formula) throws KitError { return eval(Calculator.createCalculator(), formula); } @@ -32,7 +34,7 @@ public class FormulaKit { * @return 公式计算后的结果值 * @throws KitError 如果计算过程中出现错误,则抛出此异常 */ - public static Object eval(CalculatorProvider calculator, String formula) throws KitError { + public static @Nullable Object eval(CalculatorProvider calculator, String formula) throws KitError { try { return BaseFormula.createFormulaBuilder().build(formula).eval(calculator); } catch (UtilEvalError u) { @@ -45,7 +47,7 @@ public class FormulaKit { * @param content 公式的内容 * @return 公式对象 */ - public static FormulaProvider newFormula(Object content) { + public static @NotNull FormulaProvider newFormula(Object content) { return BaseFormula.createFormulaBuilder().build(content); } } diff --git a/src/main/java/com/fanruan/api/cal/ParameterKit.java b/src/main/java/com/fanruan/api/cal/ParameterKit.java index 430986f..d3ce791 100644 --- a/src/main/java/com/fanruan/api/cal/ParameterKit.java +++ b/src/main/java/com/fanruan/api/cal/ParameterKit.java @@ -4,6 +4,7 @@ import com.fr.base.ParameterHelper; import com.fr.base.ParameterMapNameSpace; import com.fr.stable.ParameterProvider; import com.fr.stable.script.NameSpace; +import org.jetbrains.annotations.NotNull; import java.util.Map; @@ -20,7 +21,7 @@ public class ParameterKit { * @param text 公式内容 * @return 参数数组 */ - public static ParameterProvider[] analyze4ParametersFromFormula(String text) { + public static @NotNull ParameterProvider[] analyze4ParametersFromFormula(String text) { return ParameterHelper.analyze4ParametersFromFormula(text); } @@ -29,7 +30,7 @@ public class ParameterKit { * @param map 参数键值对 * @return 名字空间,用于传递给算子做计算 */ - public static NameSpace createParameterMapNameSpace(Map map) { + public static @NotNull NameSpace createParameterMapNameSpace(Map map) { return ParameterMapNameSpace.create(map); } } diff --git a/src/main/java/com/fanruan/api/data/TableDataKit.java b/src/main/java/com/fanruan/api/data/TableDataKit.java index 936c9c2..6039b01 100644 --- a/src/main/java/com/fanruan/api/data/TableDataKit.java +++ b/src/main/java/com/fanruan/api/data/TableDataKit.java @@ -6,6 +6,7 @@ import com.fr.data.api.TableDataAssist; import com.fr.script.Calculator; import com.fr.stable.script.CalculatorProvider; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author richie @@ -25,7 +26,7 @@ public class TableDataKit { * @param name 数据集名字 * @return 数据集 */ - public static TableData getTableData(@NotNull CalculatorProvider cal, String name) { + public static @Nullable TableData getTableData(@NotNull CalculatorProvider cal, String name) { return TableDataAssist.getTableData((Calculator) cal, name); } @@ -39,7 +40,7 @@ public class TableDataKit { * @param name 数据集名字 * @return 数据集 */ - public static TableData getTableData(@NotNull TableDataSource source, String name) { + public static @Nullable TableData getTableData(@NotNull TableDataSource source, String name) { return TableDataAssist.getTableData(source, name); } } diff --git a/src/main/java/com/fanruan/api/login/LoginKit.java b/src/main/java/com/fanruan/api/login/LoginKit.java new file mode 100644 index 0000000..be128c1 --- /dev/null +++ b/src/main/java/com/fanruan/api/login/LoginKit.java @@ -0,0 +1,46 @@ +package com.fanruan.api.login; + +import com.fr.decision.authorize.Passport; +import com.fr.decision.authorize.impl.HttpPassport; +import com.fr.decision.config.FSConfig; +import org.jetbrains.annotations.Nullable; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-08-16 + */ +public class LoginKit { + + /** + * 获取决策平台设置的认证类型 + * @return 认证对象 + */ + public static Passport getCurrentPassport() { + return FSConfig.getInstance().getPassport(); + } + + /** + * 获取http认证的地址 + * @return http认证地址 + */ + public static @Nullable String getHttpPassportUrl() { + Passport passport = getCurrentPassport(); + if (passport instanceof HttpPassport) { + return ((HttpPassport) passport).getUrl(); + } + return null; + } + + /** + * 获取http认证的秘钥 + * @return http认证地址 + */ + public static @Nullable String getHttpPassportKey() { + Passport passport = getCurrentPassport(); + if (passport instanceof HttpPassport) { + return ((HttpPassport) passport).getPublicKey(); + } + return null; + } +} diff --git a/src/main/java/com/fanruan/api/net/NetworkKit.java b/src/main/java/com/fanruan/api/net/NetworkKit.java index 0ac9238..d534934 100644 --- a/src/main/java/com/fanruan/api/net/NetworkKit.java +++ b/src/main/java/com/fanruan/api/net/NetworkKit.java @@ -1,6 +1,7 @@ package com.fanruan.api.net; import com.fr.data.NetworkHelper; +import org.jetbrains.annotations.Nullable; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -80,7 +81,7 @@ public class NetworkKit { * @param req HTTP请求 * @return session编号 */ - public static String getHTTPRequestSessionIDParameter(HttpServletRequest req) { + public static @Nullable String getHTTPRequestSessionIDParameter(HttpServletRequest req) { return NetworkHelper.getHTTPRequestSessionIDParameter(req); } @@ -102,7 +103,7 @@ public class NetworkKit { * @param paraName 参数名 * @return 字符型参数值 */ - public static String getHTTPRequestParameter(HttpServletRequest req, String paraName) { + public static @Nullable String getHTTPRequestParameter(HttpServletRequest req, String paraName) { return NetworkHelper.getHTTPRequestParameter(req, paraName); } @@ -113,7 +114,7 @@ public class NetworkKit { * @param paraNames 参数列表 * @return 字符型参数值 */ - public static String getHTTPRequestParameter(HttpServletRequest req, String... paraNames) { + public static @Nullable String getHTTPRequestParameter(HttpServletRequest req, String... paraNames) { return NetworkHelper.getHTTPRequestParameter(req, paraNames); } } diff --git a/src/main/java/com/fanruan/api/session/SessionKit.java b/src/main/java/com/fanruan/api/session/SessionKit.java index 0ae6c7c..55c00bc 100644 --- a/src/main/java/com/fanruan/api/session/SessionKit.java +++ b/src/main/java/com/fanruan/api/session/SessionKit.java @@ -3,6 +3,7 @@ package com.fanruan.api.session; import com.fr.stable.web.SessionProvider; import com.fr.web.core.SessionPoolManager; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author richie @@ -16,7 +17,7 @@ public class SessionKit { * @param sessionID 会话唯一标识符 * @return 会话对象 */ - public static SessionProvider getSession(@NotNull String sessionID) { + public static @Nullable SessionProvider getSession(@NotNull String sessionID) { return SessionPoolManager.getSessionIDInfor(sessionID, SessionProvider.class); } } diff --git a/src/main/java/com/fanruan/api/util/GeneralKit.java b/src/main/java/com/fanruan/api/util/GeneralKit.java index 6e2950f..7b69760 100644 --- a/src/main/java/com/fanruan/api/util/GeneralKit.java +++ b/src/main/java/com/fanruan/api/util/GeneralKit.java @@ -1,5 +1,9 @@ package com.fanruan.api.util; +import com.fr.general.GeneralUtils; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + import java.io.IOException; /** @@ -14,8 +18,8 @@ public class GeneralKit { * * @return 表示系统MAC地址的字符串 */ - public static String getMacAddress() throws IOException { - return com.fr.general.GeneralUtils.getMacAddress(); + public static @NotNull String getMacAddress() throws IOException { + return GeneralUtils.getMacAddress(); } /** @@ -23,16 +27,26 @@ public class GeneralKit { * @param obj 待转换的对象 * @return 文本值 */ - public static String objectToString(Object obj) { - return com.fr.general.GeneralUtils.objectToString(obj); + public static @NotNull String objectToString(Object obj) { + return GeneralUtils.objectToString(obj); } /** - * 任意对象转换为数值 + * 任意对象转换为数值,如果无法转换为数值,就返回0 * @param obj 待转换的对象 * @return 数值 */ - public static Number objectToNumber(Object obj) { - return com.fr.general.GeneralUtils.objectToNumber(obj); + public static @NotNull Number objectToNumber(Object obj) { + return GeneralUtils.objectToNumber(obj); + } + + /** + * 任意对象转换为数值,如果无法转换为数值,根据returnNull参数决定,返回0或者返回null + * @param obj 待转换的对象 + * @param returnNull 无法转换时,是否返回null + * @return 数值对象或者null + */ + public static @Nullable Number objectToNumber(Object obj, boolean returnNull) { + return GeneralUtils.objectToNumber(obj, returnNull); } }