diff --git a/jhinno-openapi-java-sdk/pom.xml b/jhinno-openapi-java-sdk/pom.xml index 12c6124..73dec3e 100644 --- a/jhinno-openapi-java-sdk/pom.xml +++ b/jhinno-openapi-java-sdk/pom.xml @@ -5,7 +5,7 @@ 4.0.0 jhinno-openapi-java-sdk - 2.0.3 + 2.0.4 jar Jhinno OpenAPI SDK for Java The Jhinno OpenAPI SDK for Java used for accessing Jhinno OpenApi Service diff --git a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/AuthType.java b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/AuthType.java index b964e4c..e43bb05 100644 --- a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/AuthType.java +++ b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/AuthType.java @@ -2,17 +2,18 @@ package com.jhinno.sdk.openapi; /** * 目前Appform的认证类型有两个,Token模式和AK/SK的模式。 + * 使用AK/SK的模式需要应用门户安装API接口安全插件,并且需要配置AK/SK信息。 * 推荐使用AK/SK的模式,Token模式后续将被弃用 */ public enum AuthType { /** - * Token模式 + * Token模式,不推荐使用,后续将被弃用 */ TOKEN_MODE, /** - * AK/SK模式 + * AK/SK模式,推荐使用,但需要服务端安装接口安全插件 */ ACCESS_SECRET_MODE, diff --git a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/JHApiExecution.java b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/JHApiExecution.java new file mode 100644 index 0000000..89aaa62 --- /dev/null +++ b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/JHApiExecution.java @@ -0,0 +1,12 @@ +package com.jhinno.sdk.openapi; + +import com.jhinno.sdk.openapi.api.JHRequestExecution; + +public interface JHApiExecution { + + /** + * 初始化API执行器 + */ + void init(JHRequestExecution execution); + +} diff --git a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/JHApiExecutionManage.java b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/JHApiExecutionManage.java new file mode 100644 index 0000000..0a06a1e --- /dev/null +++ b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/JHApiExecutionManage.java @@ -0,0 +1,105 @@ +package com.jhinno.sdk.openapi; + +import java.util.HashMap; +import java.util.Map; + +import com.jhinno.sdk.openapi.api.JHRequestExecution; +import com.jhinno.sdk.openapi.api.app.JHAppApiExecution; +import com.jhinno.sdk.openapi.api.data.JHDataApiExecution; +import com.jhinno.sdk.openapi.api.file.JHFileApiExecution; +import com.jhinno.sdk.openapi.api.job.JHJobApiExecution; +import com.jhinno.sdk.openapi.api.organization.JHDepartmentApiExecution; +import com.jhinno.sdk.openapi.api.organization.JHUserApiExecution; +import com.jhinno.sdk.openapi.client.JHApiClient; +import com.jhinno.sdk.openapi.client.JHApiHttpClient; + +public class JHApiExecutionManage { + + public static final Map, JHApiExecution> API_CLIENT_MAP = new HashMap<>(); + public final JHRequestExecution EXECUTION; + + /** + * 创建一个带有默认HTTP客户端的API执行管理器 + * + * @param appformBaseUrl 景行API的URL + */ + public JHApiExecutionManage(String appformBaseUrl) { + JHApiClient client = new JHApiClient(appformBaseUrl); + client.initDefaultApiClient(); + EXECUTION = new JHRequestExecution(client); + initApiExecution(); + } + + /** + * 创建一个带有自定义HTTP客户端的API执行管理器 + * + * @param httpClient 自定义HTTP客户端 + * @param appformBaseUrl 景行API的URL + */ + public JHApiExecutionManage(JHApiHttpClient httpClient, String appformBaseUrl) { + JHApiClient client = new JHApiClient(appformBaseUrl); + client.setApiHttpClient(httpClient); + EXECUTION = new JHRequestExecution(client); + EXECUTION.setAuthType(AuthType.TOKEN_MODE); + initApiExecution(); + } + + /** + * 初始化默认的执行器 + */ + private void initApiExecution() { + API_CLIENT_MAP.put(JHAppApiExecution.class, new JHAppApiExecution()); + API_CLIENT_MAP.put(JHDataApiExecution.class, new JHDataApiExecution()); + API_CLIENT_MAP.put(JHFileApiExecution.class, new JHFileApiExecution()); + API_CLIENT_MAP.put(JHJobApiExecution.class, new JHJobApiExecution()); + API_CLIENT_MAP.put(JHDepartmentApiExecution.class, new JHDepartmentApiExecution()); + API_CLIENT_MAP.put(JHUserApiExecution.class, new JHUserApiExecution()); + API_CLIENT_MAP.forEach((key, value) -> { + value.init(EXECUTION); + }); + } + + /** + * 配置API执行器 + * + * @param configurator API执行器配置器 + */ + public void configureApiExecution(ApiExecutionConfigurator configurator) { + configurator.configure(EXECUTION); + } + + /** + * 注册自定义的执行器 + * + * @param execution 自定义的执行器实例 + */ + public void registerApiExecution(JHApiExecution execution) { + execution.init(EXECUTION); + API_CLIENT_MAP.put(execution.getClass(), execution); + } + + /** + * 获取一个特定的执行器用于调用接口 + * + * @param 执行器的类型 + * @param clazz 执行器的类 + * @return 执行器实例 + */ + public T getApiExecution(Class clazz) { + return (T) API_CLIENT_MAP.get(clazz); + } + + /** + * API执行器配置器接口,用于配置API执行器的参数 + */ + public static interface ApiExecutionConfigurator { + + /** + * 配置API执行器的参数 + * + * @param execution API执行器实例 + */ + void configure(JHRequestExecution execution); + + } +} diff --git a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/JHApiExecution.java b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/JHRequestExecution.java similarity index 90% rename from jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/JHApiExecution.java rename to jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/JHRequestExecution.java index 07522d6..e39bae4 100644 --- a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/JHApiExecution.java +++ b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/JHRequestExecution.java @@ -30,9 +30,9 @@ import java.util.concurrent.ConcurrentHashMap; *

* 对于定制接口,可参考以下步骤封装调用方法 *

    - *
  1. 定义一个const类同来存放接口的路径,方便后期的维护,如:{@link AppPathConstant}
  2. - *
  3. 继承{@link JHApiExecution},如:{@link JHAppApiExecution}
  4. - *
  5. 参考{@link JHAppApiExecution}中封装的方法,调用{@link JHApiExecution}中的get、post、put、delete等对新的接口封装
  6. + *
  7. 定义一个const类同来存放接口的路径,方便后期的维护,如:{@link AppPathConstant}
  8. + *
  9. 继承{@link JHRequestExecution},如:{@link JHAppApiExecution}
  10. + *
  11. 参考{@link JHAppApiExecution}中封装的方法,调用{@link JHRequestExecution}中的get、post、put、delete等对新的接口封装
  12. *
* * @author yanlongqi @@ -41,8 +41,7 @@ import java.util.concurrent.ConcurrentHashMap; */ @Data @NoArgsConstructor -public class JHApiExecution { - +public class JHRequestExecution { /** * JHApiClient实例 @@ -59,7 +58,6 @@ public class JHApiExecution { */ private int tokenResidueTime = DefaultHttpClientConfig.DEFAULT_TOKEN_RESIDUE_TIME; - /** * 是否使用服务器时间,开启可能会导致请求过慢,但是不会太慢,默认token会有缓存 */ @@ -74,7 +72,7 @@ public class JHApiExecution { /** * 接口请求的认证类型 */ - private AuthType authType = AuthType.ACCESS_SECRET_MODE; + private AuthType authType = AuthType.TOKEN_MODE; /** * 访问密钥 @@ -86,17 +84,15 @@ public class JHApiExecution { */ private String accessKeySecret; - /** * 获取一个执行器的实例 * * @param jhApiClient 请求的客户端 */ - protected JHApiExecution(JHApiClient jhApiClient) { + public JHRequestExecution(JHApiClient jhApiClient) { this.jhApiClient = jhApiClient; } - /** * 用户令牌的缓存 */ @@ -127,13 +123,15 @@ public class JHApiExecution { int tokenEffectiveTime = (tokenTimeout - tokenResidueTime) * 60 * 1000; // 如果是强制获取、用户令牌为空、用户令牌过期等,则获取令牌 - if (isForceGetToken || tokenInfo == null || System.currentTimeMillis() - tokenInfo.getCurrentTimestamp() > tokenEffectiveTime) { + if (isForceGetToken || tokenInfo == null + || System.currentTimeMillis() - tokenInfo.getCurrentTimestamp() > tokenEffectiveTime) { Map params = new HashMap<>(2); params.put("timeout", tokenTimeout); String currentTimeMillis = getCurrentTimeMillis(); String beforeEncryption = String.format(CommonConstant.TokenUserFormat, username, currentTimeMillis); try { - SecretKeySpec secretKey = new SecretKeySpec(CommonConstant.DEFAULT_AES_KEY.getBytes(StandardCharsets.UTF_8), CommonConstant.AES_ALGORITHM); + SecretKeySpec secretKey = new SecretKeySpec( + CommonConstant.DEFAULT_AES_KEY.getBytes(StandardCharsets.UTF_8), CommonConstant.AES_ALGORITHM); Cipher cipher = Cipher.getInstance(CommonConstant.AES_ECB_PADDING); cipher.init(Cipher.ENCRYPT_MODE, secretKey); byte[] encryptBytes = cipher.doFinal(beforeEncryption.getBytes(StandardCharsets.UTF_8)); @@ -154,7 +152,6 @@ public class JHApiExecution { return tokenInfo.getToken(); } - /** * @return */ @@ -165,7 +162,6 @@ public class JHApiExecution { return jhApiClient.getAppformServerCurrentTimeMillis(); } - /** * 构建一个带token的请求头 * @@ -173,7 +169,7 @@ public class JHApiExecution { * @param isContentType 是否携带默认的Content-type,默认为{@link ContentType#APPLICATION_JSON} * @return 请求头 */ - protected Map getHeaders(String username, boolean isContentType) { + public Map getHeaders(String username, boolean isContentType) { Map headers = new HashMap<>(); // 默认请求json数据 if (isContentType) { @@ -202,7 +198,6 @@ public class JHApiExecution { return headers; } - /** * 获取签名 * @@ -211,11 +206,13 @@ public class JHApiExecution { * @return 签名 */ public String getsSignature(String username, String currentTimeMillis) { - SecretKeySpec secretKey = new SecretKeySpec(accessKeySecret.getBytes(StandardCharsets.UTF_8), CommonConstant.HMAC_SHA_256_ALGORITHM); + SecretKeySpec secretKey = new SecretKeySpec(accessKeySecret.getBytes(StandardCharsets.UTF_8), + CommonConstant.HMAC_SHA_256_ALGORITHM); try { Mac mac = Mac.getInstance(CommonConstant.HMAC_SHA_256_ALGORITHM); mac.init(secretKey); - String beforeSignature = String.format(CommonConstant.SIGNATURE_FORMAT, accessKey, username, currentTimeMillis); + String beforeSignature = String.format(CommonConstant.SIGNATURE_FORMAT, accessKey, username, + currentTimeMillis); byte[] digest = mac.doFinal(beforeSignature.getBytes(StandardCharsets.UTF_8)); return Hex.encodeHexString(digest); } catch (Exception e) { @@ -229,7 +226,7 @@ public class JHApiExecution { * @param username 用户名 * @return 请求头 */ - protected Map getHeaders(String username) { + public Map getHeaders(String username) { return getHeaders(username, true); } @@ -262,7 +259,6 @@ public class JHApiExecution { return result.getData(); } - /** * 发起一个有返回值的POST请求 * @@ -282,7 +278,6 @@ public class JHApiExecution { return result.getData(); } - /** * 发起一个有返回值的POST请求 * @@ -296,7 +291,6 @@ public class JHApiExecution { return post(path, username, null, type); } - /** * 发起一个没有返回值的POST请求 * @@ -306,14 +300,14 @@ public class JHApiExecution { * @param 请求体数据类型 */ public void post(String path, String username, B body) { - ResponseResult result = jhApiClient.post(path, body, getHeaders(username), new TypeReference>() { - }); + ResponseResult result = jhApiClient.post(path, body, getHeaders(username), + new TypeReference>() { + }); if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) { throw new ServiceException(path, result.getCode(), result.getMessage()); } } - /** * 发起一个没有请求体,没有数据返回的POST请求 * @@ -325,7 +319,6 @@ public class JHApiExecution { }); } - /** * 发起一个有返回值的PUT请求 * @@ -345,7 +338,6 @@ public class JHApiExecution { return result.getData(); } - /** * 发起一个有返回值的PUT请求 * @@ -368,14 +360,14 @@ public class JHApiExecution { * @param 请求体数据类型 */ public void put(String path, String username, B body) { - ResponseResult result = jhApiClient.put(path, body, getHeaders(username), new TypeReference>() { - }); + ResponseResult result = jhApiClient.put(path, body, getHeaders(username), + new TypeReference>() { + }); if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) { throw new ServiceException(path, result.getCode(), result.getMessage()); } } - /** * 发起一个没有请求体,没有数据返回的PUT请求 * @@ -387,7 +379,6 @@ public class JHApiExecution { }); } - /** * 发起一个DELETE请求,有数据返回 * @@ -405,7 +396,6 @@ public class JHApiExecution { return result.getData(); } - /** * 发起一个DELETE请求,没有数据返回 * @@ -413,14 +403,14 @@ public class JHApiExecution { * @param username 用户名 */ public void delete(String path, String username) { - ResponseResult result = jhApiClient.delete(path, getHeaders(username), new TypeReference>() { - }); + ResponseResult result = jhApiClient.delete(path, getHeaders(username), + new TypeReference>() { + }); if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) { throw new ServiceException(path, result.getCode(), result.getMessage()); } } - /** * 退出用户的登录,释放许可,当用户退出登录后,建议清除用户的token信息 * diff --git a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/app/JHAppApiExecution.java b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/app/JHAppApiExecution.java index f7f67e0..20e9b6a 100644 --- a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/app/JHAppApiExecution.java +++ b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/app/JHAppApiExecution.java @@ -4,8 +4,9 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.jhinno.sdk.openapi.ArgsException; import com.jhinno.sdk.openapi.AuthType; import com.jhinno.sdk.openapi.CommonConstant; +import com.jhinno.sdk.openapi.JHApiExecution; import com.jhinno.sdk.openapi.ServiceException; -import com.jhinno.sdk.openapi.api.JHApiExecution; +import com.jhinno.sdk.openapi.api.JHRequestExecution; import com.jhinno.sdk.openapi.api.ResponseResult; import com.jhinno.sdk.openapi.client.JHApiClient; import com.jhinno.sdk.openapi.utils.CollectionUtil; @@ -23,16 +24,12 @@ import java.util.Map; * @author yanlongqi * @date 2024/2/1 16:26 */ -@NoArgsConstructor -public class JHAppApiExecution extends JHApiExecution { +public class JHAppApiExecution implements JHApiExecution { - /** - * 获取一个执行器的实例 - * - * @param jhApiClient 请求的客户端 - */ - public JHAppApiExecution(JHApiClient jhApiClient) { - super(jhApiClient); + private JHRequestExecution execution; + + public void init(JHRequestExecution execution) { + this.execution = execution; } /** @@ -47,17 +44,19 @@ public class JHAppApiExecution extends JHApiExecution { *

* 开发阶段,主要有一下几种方式: *

    - *
  • 使用js的 `window.open("{@link AppStartedInfo#getJhappUrl()}")`
  • - *
  • 使用HTML的a标签的href
  • - *
  • 使用HTML的iframe标签的src
  • + *
  • 使用js的 `window.open("{@link AppStartedInfo#getJhappUrl()}")`
  • + *
  • 使用HTML的a标签的href
  • + *
  • 使用HTML的iframe标签的src
  • *
* 以下是使用的伪代码: + * *
      *  // 使用a标签实例代码
      *  var a = document.createElement("a");
      *  a.href = "{@link AppStartedInfo#getJhappUrl()}";
      *  a.click();
      * 
+ * *
      *  // 使用iframe标签实例代码
      *  var iframe = document.createElement("iframe");
@@ -71,6 +70,7 @@ public class JHAppApiExecution extends JHApiExecution {
      * 并使用js生产的时间,具体的参数见 {@link AppStartRequest#setCurrentTimestamp(String)}
      *
      * 

通过浏览器启动

+ * *
      *  window.open("{@link AppStartedInfo#getWebSessionUrl()}}")
      * 
@@ -82,8 +82,9 @@ public class JHAppApiExecution extends JHApiExecution { */ public AppStartedInfo desktopStart(String username, String appId, AppStartRequest appStartRequest) { String path = AppPathConstant.APPS_START_PATH.replace("{appId}", appId); - List data = post(path, username, appStartRequest, new TypeReference>>() { - }); + List data = execution.post(path, username, appStartRequest, + new TypeReference>>() { + }); if (CollectionUtil.isEmpty(data)) { throw new ServiceException(path, 500, "获取到的会话信息为空"); } @@ -94,17 +95,17 @@ public class JHAppApiExecution extends JHApiExecution { public String getWebSessionUrl(String username, String desktopId) { String webSessionUrlPath = AppPathConstant.WEB_SESSION_URL_PATH.replace("{desktopId}", desktopId); - String url = getJhApiClient().getUrl(webSessionUrlPath); + String url = execution.getJhApiClient().getUrl(webSessionUrlPath); Map params = new HashMap<>(); - AuthType authType = getAuthType(); + AuthType authType = execution.getAuthType(); if (authType == AuthType.TOKEN_MODE) { - params.put(CommonConstant.TOKEN, getToken(username)); + params.put(CommonConstant.TOKEN, execution.getToken(username)); } else if (authType == AuthType.ACCESS_SECRET_MODE) { params.put(CommonConstant.USERNAME, username); - params.put(CommonConstant.ACCESS_KEY, getAccessKey()); - String currentTimeMillis = getCurrentTimeMillis(); + params.put(CommonConstant.ACCESS_KEY, execution.getAccessKey()); + String currentTimeMillis = execution.getCurrentTimeMillis(); params.put(CommonConstant.CURRENT_TIME_MILLIS, currentTimeMillis); - params.put(CommonConstant.SIGNATURE, getsSignature(username, currentTimeMillis)); + params.put(CommonConstant.SIGNATURE, execution.getsSignature(username, currentTimeMillis)); } return JHApiClient.getUrl(url, params); } @@ -131,16 +132,16 @@ public class JHAppApiExecution extends JHApiExecution { * @return 会话列表 */ public List getDesktopList(String username) { - return get(AppPathConstant.APPS_SESSIONS_ALL_PATH, username, new TypeReference>>() { - }); + return execution.get(AppPathConstant.APPS_SESSIONS_ALL_PATH, username, + new TypeReference>>() { + }); } - /** * 使用参数查询会话列表 *
    - *
  • sessionIds 和 sessionName 不能同时为空
  • - *
  • 开启密级后,仅能查看比自己密级低以及和自己密级一致的会话
  • + *
  • sessionIds 和 sessionName 不能同时为空
  • + *
  • 开启密级后,仅能查看比自己密级低以及和自己密级一致的会话
  • *
* * @param username 用户名 @@ -157,11 +158,10 @@ public class JHAppApiExecution extends JHApiExecution { params.put("sessionName", sessionName); } String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_PATH, params); - return get(path, username, new TypeReference>>() { + return execution.get(path, username, new TypeReference>>() { }); } - /** * 根据会话列表查询会话列表 *

@@ -179,7 +179,7 @@ public class JHAppApiExecution extends JHApiExecution { } params.put("sessionIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, ids)); String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_IDS_PATH, params); - return get(path, username, new TypeReference>>() { + return execution.get(path, username, new TypeReference>>() { }); } @@ -201,16 +201,16 @@ public class JHAppApiExecution extends JHApiExecution { } params.put("sessionName", sessionName); String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_NAME_PATH, params); - return get(path, username, new TypeReference>>() { + return execution.get(path, username, new TypeReference>>() { }); } /** * 会话共享 *

    - *
  • 调用该接口需要打开景行会话共享的功能
  • - *
  • observers 和 interacts 不能同时为空
  • - *
  • 会话共享有密级限制,仅能将会话共享给比会话密级高的用户
  • + *
  • 调用该接口需要打开景行会话共享的功能
  • + *
  • observers 和 interacts 不能同时为空
  • + *
  • 会话共享有密级限制,仅能将会话共享给比会话密级高的用户
  • *
* * @param username 用户名 @@ -219,7 +219,8 @@ public class JHAppApiExecution extends JHApiExecution { * @param interacts 协作者列表 (非必填) * @param isTransfer 是否传递操作权(不确定,需要咨询产品,非必填) */ - public void shareDesktop(String username, String sessionId, List observers, List interacts, String isTransfer) { + public void shareDesktop(String username, String sessionId, List observers, List interacts, + String isTransfer) { if (StringUtils.isBlank(sessionId)) { throw new ArgsException("sessionId为必填字段"); } @@ -233,16 +234,16 @@ public class JHAppApiExecution extends JHApiExecution { if (StringUtils.isBlank(isTransfer)) { params.put("isTransfer", isTransfer); } - String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_SHARE_PATH.replace("{sessionId}", sessionId), params); - post(path, username); + String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_SHARE_PATH.replace("{sessionId}", sessionId), + params); + execution.post(path, username); } - /** * 取消会话共享 *
    - *
  • 调用该接口需要打开景行会话共享的功能
  • - *
  • 开启密级后,仅能操作比自己密级低或者和自己密级一致的会话
  • + *
  • 调用该接口需要打开景行会话共享的功能
  • + *
  • 开启密级后,仅能操作比自己密级低或者和自己密级一致的会话
  • *
* * @param username 用户名 @@ -253,14 +254,14 @@ public class JHAppApiExecution extends JHApiExecution { throw new ArgsException("sessionId为必填字段"); } String path = AppPathConstant.APPS_SESSIONS_CANCEL_SHARE_PATH.replace("{sessionId}", sessionId); - put(path, username); + execution.put(path, username); } /** * 传递会话操作权 *
    - *
  • 调用该接口需要打开景行会话共享的功能
  • - *
  • 开启密级后,仅能操作比自己密级低或者和自己密级一致的会话
  • + *
  • 调用该接口需要打开景行会话共享的功能
  • + *
  • 开启密级后,仅能操作比自己密级低或者和自己密级一致的会话
  • *
* * @param username 用户名 @@ -278,10 +279,9 @@ public class JHAppApiExecution extends JHApiExecution { Map params = new HashMap<>(1); params.put("interact", interact); path = JHApiClient.getUrl(path, params); - put(path, username); + execution.put(path, username); } - /** * 连接会话 * @@ -294,8 +294,9 @@ public class JHAppApiExecution extends JHApiExecution { throw new ArgsException("sessionId为必填字段"); } String path = AppPathConstant.APPS_SESSIONS_CONNECT_JHAPP_PATH.replace("{sessionId}", sessionId); - List list = get(path, username, new TypeReference>>() { - }); + List list = execution.get(path, username, + new TypeReference>>() { + }); if (CollectionUtil.isEmpty(list)) { throw new ServiceException(path, 500, "获取到的会话信息为空"); } @@ -305,7 +306,6 @@ public class JHAppApiExecution extends JHApiExecution { return appStartedInfo; } - /** * 断开会话连接(作业/应用) *

@@ -320,10 +320,9 @@ public class JHAppApiExecution extends JHApiExecution { throw new ArgsException("sessionId为必填字段"); } String path = AppPathConstant.APPS_SESSIONS_DISCONNECT_PATH.replace("{sessionId}", sessionId); - put(path, username); + execution.put(path, username); } - /** * 通过应用id批量断开会话(作业/应用) *

@@ -340,10 +339,9 @@ public class JHAppApiExecution extends JHApiExecution { Map params = new HashMap<>(1); params.put("sessionIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, sessionIds)); String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_DISCONNECT_IDS_PATH, params); - put(path, username); + execution.put(path, username); } - /** * 注销会话 *

@@ -358,10 +356,9 @@ public class JHAppApiExecution extends JHApiExecution { throw new ArgsException("sessionId为必填字段"); } String path = AppPathConstant.APPS_SESSIONS_DESTROY_PATH.replace("{sessionId}", sessionId); - put(path, username); + execution.put(path, username); } - /** * 批量注销会话 * @@ -375,10 +372,9 @@ public class JHAppApiExecution extends JHApiExecution { Map params = new HashMap<>(1); params.put("sessionIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, sessionIds)); String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_DESTROY_IDS_PATH, params); - put(path, username); + execution.put(path, username); } - /** * 获取当前用户的应用列表 * @@ -386,11 +382,11 @@ public class JHAppApiExecution extends JHApiExecution { * @return 应用列表 */ public List getAppList(String username) { - return get(AppPathConstant.APPS_LIST_PATH, username, new TypeReference>>() { - }); + return execution.get(AppPathConstant.APPS_LIST_PATH, username, + new TypeReference>>() { + }); } - /** * 获取应用链接 * @@ -403,8 +399,9 @@ public class JHAppApiExecution extends JHApiExecution { throw new ArgsException("appName为必填字段"); } String path = AppPathConstant.APPS_GET_URL_PATH.replace("{appName}", appName); - List> apps = get(path, username, new TypeReference>>>() { - }); + List> apps = execution.get(path, username, + new TypeReference>>>() { + }); if (CollectionUtil.isEmpty(apps)) { throw new ServiceException(path, 500, "应用信息为空!"); } @@ -435,7 +432,7 @@ public class JHAppApiExecution extends JHApiExecution { params.put("suffixes", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, suffixes)); } String path = JHApiClient.getUrl(AppPathConstant.APPS_SUFFIXES_PATH, params); - return get(path, username, new TypeReference>>() { + return execution.get(path, username, new TypeReference>>() { }); } @@ -450,7 +447,6 @@ public class JHAppApiExecution extends JHApiExecution { return getUseLabelList(username, Arrays.asList(labels)); } - /** * 根据用途查询应用 * @@ -464,7 +460,7 @@ public class JHAppApiExecution extends JHApiExecution { params.put("use_labels", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, labels)); } String path = JHApiClient.getUrl(AppPathConstant.APP_USE_LABEL_PATH, params); - return get(path, username, new TypeReference>>() { + return execution.get(path, username, new TypeReference>>() { }); } } diff --git a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/data/JHDataApiExecution.java b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/data/JHDataApiExecution.java index 1cd5d3c..efc0ab0 100644 --- a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/data/JHDataApiExecution.java +++ b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/data/JHDataApiExecution.java @@ -3,8 +3,9 @@ package com.jhinno.sdk.openapi.api.data; import com.fasterxml.jackson.core.type.TypeReference; import com.jhinno.sdk.openapi.ArgsException; import com.jhinno.sdk.openapi.CommonConstant; +import com.jhinno.sdk.openapi.JHApiExecution; import com.jhinno.sdk.openapi.ServiceException; -import com.jhinno.sdk.openapi.api.JHApiExecution; +import com.jhinno.sdk.openapi.api.JHRequestExecution; import com.jhinno.sdk.openapi.api.ResponseResult; import com.jhinno.sdk.openapi.client.JHApiClient; import com.jhinno.sdk.openapi.utils.CollectionUtil; @@ -23,15 +24,12 @@ import java.util.Map; * @date 2024/2/4 17:09 */ @NoArgsConstructor -public class JHDataApiExecution extends JHApiExecution { +public class JHDataApiExecution implements JHApiExecution { - /** - * 获取一个执行器的实例 - * - * @param jhApiClient 请求的客户端 - */ - public JHDataApiExecution(JHApiClient jhApiClient) { - super(jhApiClient); + private JHRequestExecution execution; + + public void init(JHRequestExecution execution) { + this.execution = execution; } /** @@ -41,11 +39,11 @@ public class JHDataApiExecution extends JHApiExecution { * @return 用户数据目录列表 */ public List getSpoolersData(String username) { - return get(DataPathConstant.DATA_SPOOLERS_PATH, username, new TypeReference>>() { - }); + return execution.get(DataPathConstant.DATA_SPOOLERS_PATH, username, + new TypeReference>>() { + }); } - /** * 根据作业id查作业数据目录信息 * @@ -58,8 +56,9 @@ public class JHDataApiExecution extends JHApiExecution { throw new ArgsException("jobId不能为空!"); } String path = DataPathConstant.DATA_SPOOLER_JOB_ID_PATH.replace("{jobId}", jobId); - List list = get(path, username, new TypeReference>>() { - }); + List list = execution.get(path, username, + new TypeReference>>() { + }); if (CollectionUtil.isEmpty(list)) { throw new ServiceException(path, 500, "作业数据目录信息为空!"); } @@ -80,7 +79,7 @@ public class JHDataApiExecution extends JHApiExecution { Map params = new HashMap<>(1); params.put("jobIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, jobIds)); String path = JHApiClient.getUrl(DataPathConstant.DATA_SPOOLERS_LIST_PATH, params); - return get(path, username, new TypeReference>>() { + return execution.get(path, username, new TypeReference>>() { }); } @@ -98,15 +97,15 @@ public class JHDataApiExecution extends JHApiExecution { Map params = new HashMap<>(1); params.put("name", dataName); String path = JHApiClient.getUrl(DataPathConstant.DATA_SPOOLERS_NAME_PATH, params); - List list = get(path, username, new TypeReference>>() { - }); + List list = execution.get(path, username, + new TypeReference>>() { + }); if (CollectionUtil.isEmpty(list)) { throw new ServiceException(path, 500, "作业数据目录信息为空!"); } return list.get(0); } - /** * 立即删除作业数据目录 * @@ -118,11 +117,10 @@ public class JHDataApiExecution extends JHApiExecution { throw new ArgsException("jobId不能为空!"); } String path = DataPathConstant.DATA_SPOOLERS_DELETE_ID_PATH.replace("{id}", jobId); - get(path, username, new TypeReference>() { + execution.get(path, username, new TypeReference>() { }); } - /** * 设置用户数据目录的过期时间,也给以通过设置过期时间来删除用户数据区 * @@ -141,7 +139,7 @@ public class JHDataApiExecution extends JHApiExecution { params.put("id", jobId); params.put("expiration_time", expirationTime); String path = JHApiClient.getUrl(DataPathConstant.DATA_SPOOLERS_PURGE_PATH, params); - get(path, username, new TypeReference>() { + execution.get(path, username, new TypeReference>() { }); } diff --git a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/file/JHFileApiExecution.java b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/file/JHFileApiExecution.java index 8b4c206..4869304 100644 --- a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/file/JHFileApiExecution.java +++ b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/file/JHFileApiExecution.java @@ -3,8 +3,9 @@ package com.jhinno.sdk.openapi.api.file; import com.fasterxml.jackson.core.type.TypeReference; import com.jhinno.sdk.openapi.ArgsException; import com.jhinno.sdk.openapi.CommonConstant; +import com.jhinno.sdk.openapi.JHApiExecution; import com.jhinno.sdk.openapi.ServiceException; -import com.jhinno.sdk.openapi.api.JHApiExecution; +import com.jhinno.sdk.openapi.api.JHRequestExecution; import com.jhinno.sdk.openapi.api.ResponseResult; import com.jhinno.sdk.openapi.client.JHApiClient; import com.jhinno.sdk.openapi.utils.CollectionUtil; @@ -26,13 +27,14 @@ import java.util.Map; * @date 2024/2/4 18:58 */ @NoArgsConstructor -public class JHFileApiExecution extends JHApiExecution { +public class JHFileApiExecution implements JHApiExecution { - public JHFileApiExecution(JHApiClient jhApiClient) { - super(jhApiClient); + private JHRequestExecution execution; + + public void init(JHRequestExecution execution) { + this.execution = execution; } - /** * 重命名文件 * @@ -50,10 +52,9 @@ public class JHFileApiExecution extends JHApiExecution { Map body = new HashMap<>(2); body.put("oldFileName", sourceFileNamePath); body.put("newFileName", targetFileName); - put(FilePathConstant.FILE_RENAME_PATH, username, body); + execution.put(FilePathConstant.FILE_RENAME_PATH, username, body); } - /** * 删除文件 * @@ -67,10 +68,9 @@ public class JHFileApiExecution extends JHApiExecution { Map params = new HashMap<>(1); params.put("fileName", sourceFilePath); String path = JHApiClient.getUrl(FilePathConstant.FILE_DELETE_PATH, params); - delete(path, username); + execution.delete(path, username); } - /** * 拷贝文件到目标文件夹 * @@ -88,10 +88,9 @@ public class JHFileApiExecution extends JHApiExecution { Map body = new HashMap<>(2); body.put("sourceFileName", sourceFilePath); body.put("targetDirectory", targetDirectoryPath); - put(FilePathConstant.FILE_COPY_PATH, username, body); + execution.put(FilePathConstant.FILE_COPY_PATH, username, body); } - /** * 获取文件列表 * @@ -106,11 +105,10 @@ public class JHFileApiExecution extends JHApiExecution { Map params = new HashMap<>(1); params.put("dir", dirPath); String path = JHApiClient.getUrl(FilePathConstant.FILE_LIST_PATH, params); - return get(path, username, new TypeReference>>() { + return execution.get(path, username, new TypeReference>>() { }); } - /** * 创建文件夹 * @@ -128,15 +126,15 @@ public class JHFileApiExecution extends JHApiExecution { if (isForce != null) { body.put("isForce", isForce.toString()); } - Map result = post(FilePathConstant.FILE_MKDIR_PATH, username, body, new TypeReference>>() { - }); + Map result = execution.post(FilePathConstant.FILE_MKDIR_PATH, username, body, + new TypeReference>>() { + }); if (CollectionUtil.isEmpty(result)) { return null; } return result.get("dirPath"); } - /** * 新建文件夹,默认不强制新建 * @@ -148,7 +146,6 @@ public class JHFileApiExecution extends JHApiExecution { return mkdir(username, dirPath, null); } - /** * 创建文件 * @@ -162,8 +159,9 @@ public class JHFileApiExecution extends JHApiExecution { } Map body = new HashMap<>(1); body.put("filePath", filePath); - Map result = post(FilePathConstant.FILE_MKFILE_PATH, username, body, new TypeReference>>() { - }); + Map result = execution.post(FilePathConstant.FILE_MKFILE_PATH, username, body, + new TypeReference>>() { + }); if (CollectionUtil.isEmpty(result)) { return null; } @@ -195,26 +193,25 @@ public class JHFileApiExecution extends JHApiExecution { body.put("isCover", isCover); } body.put("uploadPath", uploadPath); - - ResponseResult result = getJhApiClient().upload( + ResponseResult result = execution.getJhApiClient().upload( FilePathConstant.FILE_UPLOAD_PATH, "file", fileName, is, - getHeaders(username, false), + execution.getHeaders(username, false), body, new TypeReference>() { - } - ); + }); if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) { throw new ServiceException(FilePathConstant.FILE_UPLOAD_PATH, result.getCode(), result.getMessage()); } } - /** * 上传文件(不覆盖源文件) - *

源文件目录下存在相同文件则会报错

+ *

+ * 源文件目录下存在相同文件则会报错 + *

* * @param username 用户名 * @param is 文件流 @@ -232,7 +229,8 @@ public class JHFileApiExecution extends JHApiExecution { * @param uploadPath 上传路径,服务器路径 * @param isCover 是否覆盖(非必填,默认:false) */ - public void uploadFile(String username, String path, String fileName, String uploadPath, Boolean isCover) throws FileNotFoundException { + public void uploadFile(String username, String path, String fileName, String uploadPath, Boolean isCover) + throws FileNotFoundException { if (StringUtils.isBlank(path)) { throw new ArgsException("path是必填参数"); } @@ -241,25 +239,25 @@ public class JHFileApiExecution extends JHApiExecution { uploadFile(username, fileInputStream, fileName, uploadPath, isCover); } - /** * @param username 用户名 * @param path 本地文件路径 * @param fileName 文件名 * @param uploadPath 上传路径,服务器路径 */ - public void uploadFile(String username, String path, String fileName, String uploadPath) throws FileNotFoundException { + public void uploadFile(String username, String path, String fileName, String uploadPath) + throws FileNotFoundException { uploadFile(username, path, fileName, uploadPath, null); } - /** * @param username 用户名 * @param path 本地文件路径 * @param uploadPath 上传路径,服务器路径 * @param isCover 是否覆盖(非必填,默认:false) */ - public void uploadFile(String username, String path, String uploadPath, Boolean isCover) throws FileNotFoundException { + public void uploadFile(String username, String path, String uploadPath, Boolean isCover) + throws FileNotFoundException { File file = new File(path); uploadFile(username, path, file.getName(), uploadPath, isCover); } @@ -274,7 +272,6 @@ public class JHFileApiExecution extends JHApiExecution { uploadFile(username, path, file.getName(), uploadPath, null); } - /** * 获取文件下载地址 * @@ -289,8 +286,9 @@ public class JHFileApiExecution extends JHApiExecution { Map params = new HashMap<>(1); params.put("filePath", filePath); String path = JHApiClient.getUrl(FilePathConstant.FILE_DOWNLOAD_PATH, params); - Map downloadInfo = get(path, username, new TypeReference>>() { - }); + Map downloadInfo = execution.get(path, username, + new TypeReference>>() { + }); if (CollectionUtil.isEmpty(downloadInfo)) { return null; } @@ -319,10 +317,9 @@ public class JHFileApiExecution extends JHApiExecution { params.put("compressType", compressType); } String path = JHApiClient.getUrl(FilePathConstant.FILE_COMPRESS_PATH, params); - post(path, username); + execution.post(path, username); } - /** * 文件压缩 * @@ -344,7 +341,8 @@ public class JHFileApiExecution extends JHApiExecution { * @param password 密码 * @param compressType 压缩类型 (未使用以后扩展) */ - public void uncompress(String username, String sourceFilePath, String targetDirPath, Boolean isCover, String password, String compressType) { + public void uncompress(String username, String sourceFilePath, String targetDirPath, Boolean isCover, + String password, String compressType) { if (StringUtils.isBlank(sourceFilePath)) { throw new ArgsException("sourceFilePath不能为空!"); } @@ -364,10 +362,9 @@ public class JHFileApiExecution extends JHApiExecution { params.put("compressType", compressType); } String path = JHApiClient.getUrl(FilePathConstant.FILE_UNCOMPRESS_PATH, params); - post(path, username); + execution.post(path, username); } - /** * 解压文件 * @@ -377,7 +374,8 @@ public class JHFileApiExecution extends JHApiExecution { * @param isCover 是否覆盖 * @param password 密码 */ - public void uncompress(String username, String sourceFilePath, String targetDirPath, Boolean isCover, String password) { + public void uncompress(String username, String sourceFilePath, String targetDirPath, Boolean isCover, + String password) { uncompress(username, sourceFilePath, targetDirPath, isCover, password, null); } @@ -404,5 +402,3 @@ public class JHFileApiExecution extends JHApiExecution { uncompress(username, sourceFilePath, targetDirPath, null); } } - - diff --git a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/job/JHJobApiExecution.java b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/job/JHJobApiExecution.java index 107329d..b4456ba 100644 --- a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/job/JHJobApiExecution.java +++ b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/job/JHJobApiExecution.java @@ -3,8 +3,9 @@ package com.jhinno.sdk.openapi.api.job; import com.fasterxml.jackson.core.type.TypeReference; import com.jhinno.sdk.openapi.ArgsException; import com.jhinno.sdk.openapi.CommonConstant; +import com.jhinno.sdk.openapi.JHApiExecution; import com.jhinno.sdk.openapi.ServiceException; -import com.jhinno.sdk.openapi.api.JHApiExecution; +import com.jhinno.sdk.openapi.api.JHRequestExecution; import com.jhinno.sdk.openapi.api.ResponseResult; import com.jhinno.sdk.openapi.api.file.FileInfo; import com.jhinno.sdk.openapi.client.JHApiClient; @@ -22,15 +23,12 @@ import java.util.Map; * @date 2024/2/5 18:44 */ @NoArgsConstructor -public class JHJobApiExecution extends JHApiExecution { +public class JHJobApiExecution implements JHApiExecution { - /** - * 获取一个执行器的实例 - * - * @param jhApiClient 请求的客户端 - */ - public JHJobApiExecution(JHApiClient jhApiClient) { - super(jhApiClient); + private JHRequestExecution execution; + + public void init(JHRequestExecution execution) { + this.execution = execution; } /** @@ -52,8 +50,9 @@ public class JHJobApiExecution extends JHApiExecution { map.put("appId", appId); map.put("params", JsonUtil.objectToString(params)); String path = JHApiClient.getUrl(JobPathConstant.JOB_SUBMIT_PATH, map); - List> result = post(path, username, new TypeReference>>>() { - }); + List> result = execution.post(path, username, + new TypeReference>>>() { + }); if (CollectionUtil.isEmpty(result)) { throw new ServiceException(path, 500, "作业提交返回为空!"); } @@ -72,13 +71,15 @@ public class JHJobApiExecution extends JHApiExecution { throw new ArgsException("jobId不能为空!"); } String path = JobPathConstant.JOB_FIND_JOB_FILES_PATH.replace("{jobId}", jobId); - return get(path, username, new TypeReference>>() { + return execution.get(path, username, new TypeReference>>() { }); } /** * 分页查询作业列表 - *

作业名、作业状态等为非必填自动,如果为空则没有添加该查询条件

+ *

+ * 作业名、作业状态等为非必填自动,如果为空则没有添加该查询条件 + *

* * @param username 用户名 * @param page 页码(非必填,默认:1) @@ -89,7 +90,8 @@ public class JHJobApiExecution extends JHApiExecution { * @return 作业列表 * @see JobStatusEnum */ - public PageJobInfo getJobPage(String username, Integer page, Integer pageSize, String name, JobStatusEnum status, Map condition) { + public PageJobInfo getJobPage(String username, Integer page, Integer pageSize, String name, JobStatusEnum status, + Map condition) { Map params = new HashMap<>(5); if (page != null) { params.put("page", page); @@ -107,13 +109,15 @@ public class JHJobApiExecution extends JHApiExecution { params.put("condition", JsonUtil.objectToString(params)); } String path = JHApiClient.getUrl(JobPathConstant.JOB_PAGE_PATH, params); - return get(path, username, new TypeReference>() { + return execution.get(path, username, new TypeReference>() { }); } /** * 分页查询作业列表 - *

作业名、作业状态等为非必填自动,如果为空则没有添加该查询条件

+ *

+ * 作业名、作业状态等为非必填自动,如果为空则没有添加该查询条件 + *

* * @param username 用户名 * @param page 页码(非必填,默认:1) @@ -124,7 +128,8 @@ public class JHJobApiExecution extends JHApiExecution { * @return 作业列表 * @see JobStatusEnum */ - public PageJobInfo getJobPage(String username, Integer page, Integer pageSize, String name, String status, Map condition) { + public PageJobInfo getJobPage(String username, Integer page, Integer pageSize, String name, String status, + Map condition) { return getJobPage(username, page, pageSize, name, JobStatusEnum.getJobStatus(status), condition); } @@ -140,11 +145,10 @@ public class JHJobApiExecution extends JHApiExecution { throw new ArgsException("jobId不能为空!"); } String path = JobPathConstant.JOB_DETAIL_INFO_PATH.replace("{jobId}", jobId); - return get(path, username, new TypeReference>() { + return execution.get(path, username, new TypeReference>() { }); } - /** * 分页检索作业名称查询作业信息 * @@ -168,11 +172,10 @@ public class JHJobApiExecution extends JHApiExecution { } String path = JHApiClient.getUrl(JobPathConstant.JOB_LIST_BY_NAME_PATH, params); - return get(path, username, new TypeReference>>() { + return execution.get(path, username, new TypeReference>>() { }); } - /** * 分页检索作业状态 *

@@ -195,12 +198,12 @@ public class JHJobApiExecution extends JHApiExecution { if (pageSize != null) { params.put("pageSize", pageSize); } - String path = JHApiClient.getUrl(JobPathConstant.JOB_LIST_BY_STATUS_PATH.replace("{status}", status.getStatus()), params); - return get(path, username, new TypeReference>>() { + String path = JHApiClient + .getUrl(JobPathConstant.JOB_LIST_BY_STATUS_PATH.replace("{status}", status.getStatus()), params); + return execution.get(path, username, new TypeReference>>() { }); } - /** * 作业的状态(必填), * @@ -215,7 +218,6 @@ public class JHJobApiExecution extends JHApiExecution { return getJobsByStatus(username, JobStatusEnum.getJobStatus(status), page, pageSize); } - /** * 通过作业id列表查询作业列表 * @@ -230,14 +232,15 @@ public class JHJobApiExecution extends JHApiExecution { Map params = new HashMap<>(1); params.put("jobIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, jobIds)); String path = JHApiClient.getUrl(JobPathConstant.JOB_LIST_BY_IDS_PATH, params); - return get(path, username, new TypeReference>>() { + return execution.get(path, username, new TypeReference>>() { }); } /** * 操作作业 *

- * {@link JobActionEnum} 中的 静态方法{@link JobActionEnum#getJobAction(String)}可以将前端的字符转换为{@link JobActionEnum}对象 + * {@link JobActionEnum} 中的 + * 静态方法{@link JobActionEnum#getJobAction(String)}可以将前端的字符转换为{@link JobActionEnum}对象 *

* 或者使用{@link #action(String, String, String)}直接操作,但最终还是调的这个方法,我们只不过是内部做了转换而已 * @@ -254,7 +257,7 @@ public class JHJobApiExecution extends JHApiExecution { throw new ArgsException("jobId不能为空!"); } String path = JobPathConstant.JOB_ACTION_PATH.replace("{jobId}", jobId).replace("{action}", action.getAction()); - put(path, username); + execution.put(path, username); } /** @@ -268,11 +271,11 @@ public class JHJobApiExecution extends JHApiExecution { action(username, JobActionEnum.getJobAction(action), jobId); } - /** * 批量操作作业 *

- * {@link JobsActionEnum} 中的 静态方法{@link JobsActionEnum#getJobAction(String)}可以将前端的字符转换为{@link JobsActionEnum}对象 + * {@link JobsActionEnum} 中的 + * 静态方法{@link JobsActionEnum#getJobAction(String)}可以将前端的字符转换为{@link JobsActionEnum}对象 *

* 或者使用{@link #actions(String, String, List)}直接操作,但最终还是调的这个方法,我们只不过是内部做了转换而已 * @@ -289,8 +292,9 @@ public class JHJobApiExecution extends JHApiExecution { } Map params = new HashMap<>(1); params.put("jobIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, jobIds)); - String path = JHApiClient.getUrl(JobPathConstant.JOB_ACTION_IDS_PATH.replace("{action}", action.getAction()), params); - put(path, username); + String path = JHApiClient.getUrl(JobPathConstant.JOB_ACTION_IDS_PATH.replace("{action}", action.getAction()), + params); + execution.put(path, username); } /** @@ -304,7 +308,6 @@ public class JHJobApiExecution extends JHApiExecution { actions(username, JobsActionEnum.getJobAction(action), jobIds); } - /** * 查询制定作业的作业历史 * @@ -317,15 +320,15 @@ public class JHJobApiExecution extends JHApiExecution { throw new ArgsException("jobId不能为空!"); } String path = JobPathConstant.JOB_HISTORY_PATH.replace("{jobId}", jobId); - List list = get(path, username, new TypeReference>>() { - }); + List list = execution.get(path, username, + new TypeReference>>() { + }); if (CollectionUtil.isEmpty(list)) { throw new ServiceException(path, 500, "历史作业信息不存在!"); } return list.get(0); } - /** * 通过多个id查询作业历史列表 * @@ -340,7 +343,7 @@ public class JHJobApiExecution extends JHApiExecution { Map params = new HashMap<>(1); params.put("jobIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, jobIds)); String path = JHApiClient.getUrl(JobPathConstant.JOB_HISTORY_IDS_PATH, params); - return get(path, username, new TypeReference>>() { + return execution.get(path, username, new TypeReference>>() { }); } @@ -356,8 +359,9 @@ public class JHJobApiExecution extends JHApiExecution { throw new ArgsException("jobId不能为空!"); } String path = JobPathConstant.JOB_PEEK_PATH.replace("{jobId}", jobId); - ResponseResult result = getJhApiClient().get(path, getHeaders(username), new TypeReference>() { - }); + ResponseResult result = execution.getJhApiClient().get(path, execution.getHeaders(username), + new TypeReference>() { + }); if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) { throw new ServiceException(path, result.getCode(), result.getMessage()); } @@ -368,7 +372,6 @@ public class JHJobApiExecution extends JHApiExecution { return result.getMessage(); } - /** * 连接作业会话 * @@ -381,7 +384,7 @@ public class JHJobApiExecution extends JHApiExecution { throw new ArgsException("jobId不能为空!"); } String path = JobPathConstant.JOB_CONNECT_SESSION_PATH.replace("{jobId}", jobId); - return post(path, username, new TypeReference>() { + return execution.post(path, username, new TypeReference>() { }); } @@ -396,7 +399,7 @@ public class JHJobApiExecution extends JHApiExecution { throw new ArgsException("appId不能为空!"); } String path = JobPathConstant.JOB_GET_APP_FORM_PATH.replace("{appId}", appId); - return get(path, username, new TypeReference>>() { + return execution.get(path, username, new TypeReference>>() { }); } diff --git a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/organization/JHDepartmentApiExecution.java b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/organization/JHDepartmentApiExecution.java index 812bed3..d89e414 100644 --- a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/organization/JHDepartmentApiExecution.java +++ b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/organization/JHDepartmentApiExecution.java @@ -2,7 +2,8 @@ package com.jhinno.sdk.openapi.api.organization; import com.fasterxml.jackson.core.type.TypeReference; import com.jhinno.sdk.openapi.ArgsException; -import com.jhinno.sdk.openapi.api.JHApiExecution; +import com.jhinno.sdk.openapi.JHApiExecution; +import com.jhinno.sdk.openapi.api.JHRequestExecution; import com.jhinno.sdk.openapi.api.ResponseResult; import com.jhinno.sdk.openapi.client.JHApiClient; import lombok.NoArgsConstructor; @@ -20,18 +21,14 @@ import java.util.Map; * @date 2024/2/6 17:37 */ @NoArgsConstructor -public class JHDepartmentApiExecution extends JHApiExecution { +public class JHDepartmentApiExecution implements JHApiExecution { - /** - * 获取一个执行器的实例 - * - * @param jhApiClient 请求的客户端 - */ - public JHDepartmentApiExecution(JHApiClient jhApiClient) { - super(jhApiClient); + private JHRequestExecution execution; + + public void init(JHRequestExecution execution) { + this.execution = execution; } - /** * 查询用户列表 * @@ -39,11 +36,11 @@ public class JHDepartmentApiExecution extends JHApiExecution { * @return 用户列表 */ public List> getDepartmentList(String username) { - return get(DepartmentPathConstant.DEPARTMENT_PATH, username, new TypeReference>>>() { - }); + return execution.get(DepartmentPathConstant.DEPARTMENT_PATH, username, + new TypeReference>>>() { + }); } - /** * 添加部门 * @@ -51,10 +48,9 @@ public class JHDepartmentApiExecution extends JHApiExecution { * @param departmentInfo 部门信息 */ public void addDepartment(String username, AddUpdateDepartment departmentInfo) { - post(DepartmentPathConstant.DEPARTMENT_PATH, username, departmentInfo); + execution.post(DepartmentPathConstant.DEPARTMENT_PATH, username, departmentInfo); } - /** * 修改部门信息 * @@ -66,10 +62,9 @@ public class JHDepartmentApiExecution extends JHApiExecution { throw new ArgsException("departmentInfo中的depName不能为空!"); } String path = DepartmentPathConstant.DEPARTMENT_NAME_PATH.replace("{depName}", departmentInfo.getDepName()); - put(path, username, departmentInfo); + execution.put(path, username, departmentInfo); } - /** * 删除部门信息 * @@ -81,6 +76,6 @@ public class JHDepartmentApiExecution extends JHApiExecution { throw new ArgsException("departmentName不能为空!"); } String path = DepartmentPathConstant.DEPARTMENT_NAME_PATH.replace("{depName}", departmentName); - delete(path, username); + execution.delete(path, username); } } diff --git a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/organization/JHUserApiExecution.java b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/organization/JHUserApiExecution.java index 1ad657d..bf7ae4a 100644 --- a/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/organization/JHUserApiExecution.java +++ b/jhinno-openapi-java-sdk/src/main/java/com/jhinno/sdk/openapi/api/organization/JHUserApiExecution.java @@ -2,7 +2,8 @@ package com.jhinno.sdk.openapi.api.organization; import com.fasterxml.jackson.core.type.TypeReference; import com.jhinno.sdk.openapi.ArgsException; -import com.jhinno.sdk.openapi.api.JHApiExecution; +import com.jhinno.sdk.openapi.JHApiExecution; +import com.jhinno.sdk.openapi.api.JHRequestExecution; import com.jhinno.sdk.openapi.api.PageResult; import com.jhinno.sdk.openapi.api.ResponseResult; import com.jhinno.sdk.openapi.client.JHApiClient; @@ -21,16 +22,13 @@ import java.util.Map; * @date 2024/2/6 17:37 */ @NoArgsConstructor -public class JHUserApiExecution extends JHApiExecution { - /** - * 获取一个执行器的实例 - * - * @param jhApiClient 请求的客户端 - */ - public JHUserApiExecution(JHApiClient jhApiClient) { - super(jhApiClient); - } +public class JHUserApiExecution implements JHApiExecution { + private JHRequestExecution execution; + + public void init(JHRequestExecution execution) { + this.execution = execution; + } /** * 分页查询用户列表 @@ -53,7 +51,7 @@ public class JHUserApiExecution extends JHApiExecution { params.put("userConf", userConf); } String path = JHApiClient.getUrl(UserPathConstant.USERS_PATH, params); - return get(path, username, new TypeReference>>() { + return execution.get(path, username, new TypeReference>>() { }); } @@ -64,7 +62,7 @@ public class JHUserApiExecution extends JHApiExecution { * @param userInfo 用户信息 */ public void addUser(String username, AddUpdateUserInfo userInfo) { - post(UserPathConstant.USERS_PATH, username, userInfo); + execution.post(UserPathConstant.USERS_PATH, username, userInfo); } /** @@ -78,17 +76,16 @@ public class JHUserApiExecution extends JHApiExecution { throw new ArgsException("userInfo中userName的值不能为空"); } String path = UserPathConstant.USERS_USERNAME_PATH.replace("{username}", userInfo.getUserName()); - put(path, username, userInfo); + execution.put(path, username, userInfo); } - /** * 修改或重置用户密码 * *

    - *
  • 当type值为{@link UpdateUserPasswordType#FORCE_UPDATE_PASSWORD_TYPE}重置密码后用户再次登录需要修改密码
  • - *
  • 当type值为{@link UpdateUserPasswordType#RESET_UPDATE_PASSWORD_TYPE}重置用户的密码
  • - *
  • 当type值为空时修改用户密码
  • + *
  • 当type值为{@link UpdateUserPasswordType#FORCE_UPDATE_PASSWORD_TYPE}重置密码后用户再次登录需要修改密码
  • + *
  • 当type值为{@link UpdateUserPasswordType#RESET_UPDATE_PASSWORD_TYPE}重置用户的密码
  • + *
  • 当type值为空时修改用户密码
  • *
* 参数怎么传,还需进一步确认,此处需要增加三个重构,方便开发者调用 * @@ -98,7 +95,8 @@ public class JHUserApiExecution extends JHApiExecution { * @param password 新密码 * @param type 类型,(非必填,取值见{@link UpdateUserPasswordType}) */ - public void updateUserPassword(String username, String updatePasswordUsername, String oldPassword, String password, String type) { + public void updateUserPassword(String username, String updatePasswordUsername, String oldPassword, String password, + String type) { if (StringUtils.isBlank(updatePasswordUsername)) { throw new ArgsException("updatePasswordUsername不能为空"); } @@ -111,10 +109,9 @@ public class JHUserApiExecution extends JHApiExecution { params.put("type", type); } params.put("password", password); - put(path, username, params); + execution.put(path, username, params); } - /** * 修改用户的密码 * @@ -123,7 +120,8 @@ public class JHUserApiExecution extends JHApiExecution { * @param oldPassword 旧密码 * @param password 新密码 */ - public void updateUserPassword(String username, String updatePasswordUsername, String oldPassword, String password) { + public void updateUserPassword(String username, String updatePasswordUsername, String oldPassword, + String password) { updateUserPassword(username, updatePasswordUsername, oldPassword, password, null); } @@ -135,7 +133,8 @@ public class JHUserApiExecution extends JHApiExecution { * @param password 新的用户密码 */ public void resetForceUpdatePassword(String username, String updatePasswordUsername, String password) { - updateUserPassword(username, updatePasswordUsername, null, password, UpdateUserPasswordType.FORCE_UPDATE_PASSWORD_TYPE); + updateUserPassword(username, updatePasswordUsername, null, password, + UpdateUserPasswordType.FORCE_UPDATE_PASSWORD_TYPE); } /** @@ -146,10 +145,10 @@ public class JHUserApiExecution extends JHApiExecution { * @param password 新的用户密码 */ public void resetPassword(String username, String updatePasswordUsername, String password) { - updateUserPassword(username, updatePasswordUsername, null, password, UpdateUserPasswordType.RESET_UPDATE_PASSWORD_TYPE); + updateUserPassword(username, updatePasswordUsername, null, password, + UpdateUserPasswordType.RESET_UPDATE_PASSWORD_TYPE); } - /** * 删除用户 * @@ -160,7 +159,7 @@ public class JHUserApiExecution extends JHApiExecution { if (StringUtils.isBlank(deleteUsername)) { throw new ArgsException("deleteUsername不能为空"); } - delete(UserPathConstant.USERS_USERNAME_PATH.replace("{username}", deleteUsername), username); + execution.delete(UserPathConstant.USERS_USERNAME_PATH.replace("{username}", deleteUsername), username); } } diff --git a/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/JHClientConfig.java b/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/JHClientConfig.java index ddd70e5..463ba83 100644 --- a/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/JHClientConfig.java +++ b/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/JHClientConfig.java @@ -1,7 +1,7 @@ package com.jhinno.sdk.openapi.test; import com.jhinno.sdk.openapi.AuthType; -import com.jhinno.sdk.openapi.api.JHApiExecution; +import com.jhinno.sdk.openapi.JHApiExecutionManage; import com.jhinno.sdk.openapi.api.app.JHAppApiExecution; import com.jhinno.sdk.openapi.api.data.JHDataApiExecution; import com.jhinno.sdk.openapi.api.file.JHFileApiExecution; @@ -22,31 +22,21 @@ import java.util.Map; public class JHClientConfig { /** - * 初始化JHApi客户端 + * 创建一个API执行器管理器 */ - public static final JHApiClient client = new JHApiClient("https://172.17.0.5/appform"); - - public static final Map, JHApiExecution> jhApiClientMap = new HashMap<>(); + public static final JHApiExecutionManage API_EXECUTRON_MANAGE = new JHApiExecutionManage( + "https://192.168.87.24/appform"); public static final String ACCESS_KEY = "3f03747f147942bd8debd81b6c9c6a80"; public static final String ACCESS_KEY_SECRET = "e0681859b91c499eb1d2c8e09cea3242"; static { - client.initDefaultApiClient(); - jhApiClientMap.put(JHAppApiExecution.class, new JHAppApiExecution()); - jhApiClientMap.put(JHDataApiExecution.class, new JHDataApiExecution()); - jhApiClientMap.put(JHFileApiExecution.class, new JHFileApiExecution()); - jhApiClientMap.put(JHJobApiExecution.class, new JHJobApiExecution()); - jhApiClientMap.put(JHDepartmentApiExecution.class, new JHDepartmentApiExecution()); - jhApiClientMap.put(JHUserApiExecution.class, new JHUserApiExecution()); - - jhApiClientMap.forEach((k, v) -> { - v.setJhApiClient(client); - v.setAuthType(AuthType.ACCESS_SECRET_MODE); - v.setAccessKey(ACCESS_KEY); - v.setAccessKeySecret(ACCESS_KEY_SECRET); - v.setUsedServerTime(true); + API_EXECUTRON_MANAGE.configureApiExecution(t -> { + // 默认为使用Token模式,如何使用的Token模式,则不需要配置ACCESS_KEY和ACCESS_KEY SECRET + // t.setAuthType(AuthType.ACCESS_KEY); + t.setAccessKey(ACCESS_KEY); + t.setAccessKeySecret(ACCESS_KEY_SECRET); }); } diff --git a/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/app/AppApiTest.java b/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/app/AppApiTest.java index 1563155..a2a9d48 100644 --- a/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/app/AppApiTest.java +++ b/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/app/AppApiTest.java @@ -16,11 +16,11 @@ import java.util.List; public class AppApiTest { - /** * 获得一个调用应用接口的执行器 */ - public static final JHAppApiExecution jhAppApiExecution = (JHAppApiExecution) JHClientConfig.jhApiClientMap.get(JHAppApiExecution.class); + public static final JHAppApiExecution jhAppApiExecution = JHClientConfig.API_EXECUTRON_MANAGE + .getApiExecution(JHAppApiExecution.class); /** * 测测试使用自定义的参数启动jhadmin的Linux桌面 @@ -42,7 +42,6 @@ public class AppApiTest { System.out.println(appStartedInfo); } - /** * 测试获取用户jhadmin的会话列表 */ @@ -61,13 +60,13 @@ public class AppApiTest { System.out.println(desktopList); } - /** * 测试根据会话列表查询会话列表 */ @Test public void testGetDesktopsById() { - List desktopList = jhAppApiExecution.getDesktopsById("jhadmin", Arrays.asList("7649", "7637", "123")); + List desktopList = jhAppApiExecution.getDesktopsById("jhadmin", + Arrays.asList("7649", "7637", "123")); System.out.println(desktopList); } @@ -80,7 +79,6 @@ public class AppApiTest { System.out.println(desktopList); } - /** * 测试会话共享 */ @@ -105,7 +103,6 @@ public class AppApiTest { jhAppApiExecution.transferOperatorRight("jhadmin", "7649", "123"); } - /** * 测试链接会话 */ @@ -115,7 +112,6 @@ public class AppApiTest { System.out.println(appStartedInfo); } - /** * 测试断开会话的连接 */ @@ -132,16 +128,14 @@ public class AppApiTest { jhAppApiExecution.disconnectSessionByIds("jhadmin", Arrays.asList("123", "456")); } - /** * 测试注销会话 */ @Test public void testDestroySession() { - jhAppApiExecution.destroySession("jhadmin", "4856"); + jhAppApiExecution.destroySession("jhadmin", "63"); } - /** * 测试批量注销会话 */ @@ -159,7 +153,6 @@ public class AppApiTest { System.out.println(appList); } - /** * 测试获取应用链接 */ @@ -168,7 +161,6 @@ public class AppApiTest { System.out.println(jhAppApiExecution.getAppUrl("jhadmin", "myjobmana")); } - /** * 测试根据文件后缀取应用列表 */ @@ -177,7 +169,6 @@ public class AppApiTest { System.out.println(jhAppApiExecution.getAppInfoSuffixList("test", ".sh")); } - /** * 测试根据用途获取应用列表 */ diff --git a/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/data/DataApiTest.java b/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/data/DataApiTest.java index 593ba69..7905b29 100644 --- a/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/data/DataApiTest.java +++ b/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/data/DataApiTest.java @@ -14,7 +14,8 @@ import java.util.Arrays; */ public class DataApiTest { - public static final JHDataApiExecution execution = (JHDataApiExecution) JHClientConfig.jhApiClientMap.get(JHDataApiExecution.class); + public static final JHDataApiExecution execution =JHClientConfig.API_EXECUTRON_MANAGE + .getApiExecution(JHDataApiExecution.class); /** * 测试获取作业数据区目录列表 diff --git a/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/file/FileApiTest.java b/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/file/FileApiTest.java index 93413cb..a37ed9b 100644 --- a/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/file/FileApiTest.java +++ b/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/file/FileApiTest.java @@ -17,7 +17,8 @@ import java.util.List; */ public class FileApiTest { - private static final JHFileApiExecution execution = (JHFileApiExecution) JHClientConfig.jhApiClientMap.get(JHFileApiExecution.class); + private static final JHFileApiExecution execution = JHClientConfig.API_EXECUTRON_MANAGE + .getApiExecution(JHFileApiExecution.class); /** diff --git a/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/job/JobApiTest.java b/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/job/JobApiTest.java index 42fda86..9dcba0d 100644 --- a/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/job/JobApiTest.java +++ b/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/job/JobApiTest.java @@ -17,7 +17,8 @@ import java.util.Map; */ public class JobApiTest { - private static final JHJobApiExecution execution = (JHJobApiExecution) JHClientConfig.jhApiClientMap.get(JHJobApiExecution.class); + private static final JHJobApiExecution execution = JHClientConfig.API_EXECUTRON_MANAGE + .getApiExecution(JHJobApiExecution.class); /** * 测试提交作业 diff --git a/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/organization/DepartmentApiTest.java b/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/organization/DepartmentApiTest.java index e263728..abb1ec5 100644 --- a/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/organization/DepartmentApiTest.java +++ b/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/organization/DepartmentApiTest.java @@ -13,7 +13,8 @@ import org.junit.Test; */ public class DepartmentApiTest { - private static final JHDepartmentApiExecution execution = (JHDepartmentApiExecution) JHClientConfig.jhApiClientMap.get(JHDepartmentApiExecution.class); + private static final JHDepartmentApiExecution execution = JHClientConfig.API_EXECUTRON_MANAGE + .getApiExecution(JHDepartmentApiExecution.class); /** diff --git a/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/organization/UserApiTest.java b/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/organization/UserApiTest.java index 4e058eb..00b48d6 100644 --- a/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/organization/UserApiTest.java +++ b/jhinno-openapi-java-sdk/src/test/java/com/jhinno/sdk/openapi/test/organization/UserApiTest.java @@ -15,7 +15,8 @@ import org.junit.Test; */ public class UserApiTest { - private static final JHUserApiExecution execution = (JHUserApiExecution) JHClientConfig.jhApiClientMap.get(JHUserApiExecution.class); + private static final JHUserApiExecution execution = JHClientConfig.API_EXECUTRON_MANAGE + .getApiExecution(JHUserApiExecution.class); /** diff --git a/jhinno-openapi-sdk-spring-boot-example/pom.xml b/jhinno-openapi-sdk-spring-boot-example/pom.xml index 3658184..cf450fa 100644 --- a/jhinno-openapi-sdk-spring-boot-example/pom.xml +++ b/jhinno-openapi-sdk-spring-boot-example/pom.xml @@ -5,7 +5,7 @@ 4.0.0 cim.jhinno jhinno-openapi-sdk-spring-boot-example - 2.0.3 + 2.0.4 jar Jhinno OpenAPI SDK for Java SpringBoot Example The Jhinno OpenAPI SDK for Java used for accessing Jhinno OpenApi Service @@ -22,7 +22,7 @@ com.jhinno jhinno-openapi-sdk-spring-boot-starter - 2.0.3 + 2.0.4 diff --git a/jhinno-openapi-sdk-spring-boot-example/src/main/java/com/jhinno/sdk/openapi/example/api/extend/JHFileApiExtendExecution.java b/jhinno-openapi-sdk-spring-boot-example/src/main/java/com/jhinno/sdk/openapi/example/api/extend/JHFileApiExtendExecution.java index 2437877..641b323 100644 --- a/jhinno-openapi-sdk-spring-boot-example/src/main/java/com/jhinno/sdk/openapi/example/api/extend/JHFileApiExtendExecution.java +++ b/jhinno-openapi-sdk-spring-boot-example/src/main/java/com/jhinno/sdk/openapi/example/api/extend/JHFileApiExtendExecution.java @@ -1,15 +1,25 @@ package com.jhinno.sdk.openapi.example.api.extend; import com.fasterxml.jackson.core.type.TypeReference; -import com.jhinno.sdk.openapi.api.JHApiExecution; +import com.jhinno.sdk.openapi.JHApiExecution; +import com.jhinno.sdk.openapi.api.JHRequestExecution; import com.jhinno.sdk.openapi.api.ResponseResult; import com.jhinno.sdk.openapi.client.JHApiClient; import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; import java.util.HashMap; import java.util.Map; -public class JHFileApiExtendExecution extends JHApiExecution { +@Component +public class JHFileApiExtendExecution implements JHApiExecution { + + private JHRequestExecution execution; + + @Override + public void init(JHRequestExecution execution) { + this.execution = execution; + } public static String GET_FILE_ENV_PATH = "/ws/api/files/path/{env}"; @@ -19,11 +29,12 @@ public class JHFileApiExtendExecution extends JHApiExecution { params.put("type", type.getType()); } String url = JHApiClient.getUrl(GET_FILE_ENV_PATH.replace("{env}", env.getEnv()), params); - return get(url, username, new TypeReference>() { + return execution.get(url, username, new TypeReference>() { }); } public FilePath getFileHomeEnvPath(String username, FileSystemType type) { return getFileEnvPath(username, FileEnvType.HOME_ENV, type); } + } diff --git a/jhinno-openapi-sdk-spring-boot-example/src/main/java/com/jhinno/sdk/openapi/example/config/JHOpenapiExecutionConfig.java b/jhinno-openapi-sdk-spring-boot-example/src/main/java/com/jhinno/sdk/openapi/example/config/JHOpenapiExecutionConfig.java deleted file mode 100644 index 688a896..0000000 --- a/jhinno-openapi-sdk-spring-boot-example/src/main/java/com/jhinno/sdk/openapi/example/config/JHOpenapiExecutionConfig.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.jhinno.sdk.openapi.example.config; - -import com.jhinno.sdk.openapi.example.api.extend.JHFileApiExtendExecution; -import com.jhinno.sdk.openapi.utils.JHOpenApiConfig; -import lombok.RequiredArgsConstructor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - - -@Configuration -@RequiredArgsConstructor -public class JHOpenapiExecutionConfig { - - - @Bean - public JHFileApiExtendExecution fileApiExtendExecution(JHOpenApiConfig jhOpenApiConfig) { - return jhOpenApiConfig.configJHApiExecution(new JHFileApiExtendExecution()); - } -} diff --git a/jhinno-openapi-sdk-spring-boot-example/src/main/resources/application.yml b/jhinno-openapi-sdk-spring-boot-example/src/main/resources/application.yml index 37d8052..1b6bf67 100644 --- a/jhinno-openapi-sdk-spring-boot-example/src/main/resources/application.yml +++ b/jhinno-openapi-sdk-spring-boot-example/src/main/resources/application.yml @@ -1,6 +1,6 @@ jhinno: openapi: - server-url: https://172.17.0.5/appform - auth-type: access_secret_mode + server-url: https://192.168.87.24/appform + auth-type: token_mode access-key: 3f03747f147942bd8debd81b6c9c6a80 access-key-secret: e0681859b91c499eb1d2c8e09cea3242 \ No newline at end of file diff --git a/jhinno-openapi-sdk-spring-boot-example/src/test/java/com/jhinno/sdk/openapi/example/test/extend/JHFileApiExtendTest.java b/jhinno-openapi-sdk-spring-boot-example/src/test/java/com/jhinno/sdk/openapi/example/test/extend/JHFileApiExtendTest.java index 1011b79..e7d1eae 100644 --- a/jhinno-openapi-sdk-spring-boot-example/src/test/java/com/jhinno/sdk/openapi/example/test/extend/JHFileApiExtendTest.java +++ b/jhinno-openapi-sdk-spring-boot-example/src/test/java/com/jhinno/sdk/openapi/example/test/extend/JHFileApiExtendTest.java @@ -5,6 +5,7 @@ import com.jhinno.sdk.openapi.example.api.extend.JHFileApiExtendExecution; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import com.jhinno.sdk.openapi.api.app.JHAppApiExecution; @SpringBootTest public class JHFileApiExtendTest { @@ -12,8 +13,17 @@ public class JHFileApiExtendTest { @Autowired private JHFileApiExtendExecution jhFileApiExtendExecution; + @Autowired + private JHAppApiExecution jhAppApiExecution; + @Test void testGetFileHomeEnvPath() { System.out.println(jhFileApiExtendExecution.getFileHomeEnvPath("jhadmin", FileSystemType.SYSTEM_TYPE_LINUX)); } + + + @Test + void testStartApp() { + jhAppApiExecution.desktopStart("jhadmin","linux_desktop"); + } } diff --git a/jhinno-openapi-sdk-spring-boot-starter/pom.xml b/jhinno-openapi-sdk-spring-boot-starter/pom.xml index ef4af6a..1e378a3 100644 --- a/jhinno-openapi-sdk-spring-boot-starter/pom.xml +++ b/jhinno-openapi-sdk-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ 4.0.0 jhinno-openapi-sdk-spring-boot-starter - 2.0.3 + 2.0.4 jar Jhinno OpenAPI SDK for Java SpringBoot Starter The Jhinno OpenAPI SDK for Java used for accessing Jhinno OpenApi Service @@ -21,7 +21,7 @@ com.jhinno jhinno-openapi-java-sdk - 2.0.3 + 2.0.4 diff --git a/jhinno-openapi-sdk-spring-boot-starter/src/main/java/com/jhinno/sdk/openapi/autoconfigure/JHOpenapiClientAutoConfigure.java b/jhinno-openapi-sdk-spring-boot-starter/src/main/java/com/jhinno/sdk/openapi/autoconfigure/JHOpenapiClientAutoConfigure.java index 4cd3b8e..61f10e8 100644 --- a/jhinno-openapi-sdk-spring-boot-starter/src/main/java/com/jhinno/sdk/openapi/autoconfigure/JHOpenapiClientAutoConfigure.java +++ b/jhinno-openapi-sdk-spring-boot-starter/src/main/java/com/jhinno/sdk/openapi/autoconfigure/JHOpenapiClientAutoConfigure.java @@ -1,5 +1,6 @@ package com.jhinno.sdk.openapi.autoconfigure; +import com.jhinno.sdk.openapi.api.JHRequestExecution; import com.jhinno.sdk.openapi.client.JHApiClient; import com.jhinno.sdk.openapi.client.JHApiHttpClientImpl; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -17,7 +18,6 @@ import org.springframework.context.annotation.Configuration; @EnableConfigurationProperties(JHOpenapiProperties.class) public class JHOpenapiClientAutoConfigure { - @Bean @ConditionalOnMissingBean public JHApiClient jhApiClient(JHOpenapiProperties properties) { @@ -34,4 +34,17 @@ public class JHOpenapiClientAutoConfigure { return jhApiClient; } + @Bean + public JHRequestExecution requestExecution(JHApiClient jhApiClient, JHOpenapiProperties properties) { + JHRequestExecution requestExecution = new JHRequestExecution(jhApiClient); + requestExecution.setForceGetToken(properties.isForceGetToken()); + requestExecution.setAuthType(properties.getAuthType()); + requestExecution.setAccessKey(properties.getAccessKey()); + requestExecution.setAccessKeySecret(properties.getAccessKeySecret()); + requestExecution.setTokenTimeout(properties.getTokenTimeout()); + requestExecution.setTokenResidueTime(properties.getTokenResidueTime()); + requestExecution.setUsedServerTime(properties.isUsedServerTime()); + return requestExecution; + } + } diff --git a/jhinno-openapi-sdk-spring-boot-starter/src/main/java/com/jhinno/sdk/openapi/autoconfigure/JHOpenapiExecutionAutoconfigure.java b/jhinno-openapi-sdk-spring-boot-starter/src/main/java/com/jhinno/sdk/openapi/autoconfigure/JHOpenapiExecutionAutoconfigure.java index 716bc07..418f3f1 100644 --- a/jhinno-openapi-sdk-spring-boot-starter/src/main/java/com/jhinno/sdk/openapi/autoconfigure/JHOpenapiExecutionAutoconfigure.java +++ b/jhinno-openapi-sdk-spring-boot-starter/src/main/java/com/jhinno/sdk/openapi/autoconfigure/JHOpenapiExecutionAutoconfigure.java @@ -1,13 +1,17 @@ package com.jhinno.sdk.openapi.autoconfigure; +import com.jhinno.sdk.openapi.JHApiExecution; +import com.jhinno.sdk.openapi.api.JHRequestExecution; import com.jhinno.sdk.openapi.api.app.JHAppApiExecution; import com.jhinno.sdk.openapi.api.data.JHDataApiExecution; import com.jhinno.sdk.openapi.api.file.JHFileApiExecution; import com.jhinno.sdk.openapi.api.job.JHJobApiExecution; import com.jhinno.sdk.openapi.api.organization.JHDepartmentApiExecution; import com.jhinno.sdk.openapi.api.organization.JHUserApiExecution; -import com.jhinno.sdk.openapi.utils.JHOpenApiConfig; +import com.jhinno.sdk.openapi.client.JHApiClient; import lombok.RequiredArgsConstructor; + +import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -19,37 +23,45 @@ import org.springframework.context.annotation.Configuration; */ @Configuration @RequiredArgsConstructor -public class JHOpenapiExecutionAutoconfigure { +public class JHOpenapiExecutionAutoconfigure implements BeanPostProcessor { + private final JHRequestExecution jhRequestExecution; - @Bean - public JHAppApiExecution appApiExecution(JHOpenApiConfig jhOpenApiConfig) { - return jhOpenApiConfig.configJHApiExecution(new JHAppApiExecution()); + public Object postProcessBeforeInitialization(Object bean, String beanName) { + if (bean instanceof JHApiExecution) { + ((JHApiExecution) bean).init(jhRequestExecution); + } + return bean; } @Bean - public JHDataApiExecution dataApiExecution(JHOpenApiConfig jhOpenApiConfig) { - return jhOpenApiConfig.configJHApiExecution(new JHDataApiExecution()); - } - - - @Bean - public JHFileApiExecution fileApiExecution(JHOpenApiConfig jhOpenApiConfig) { - return jhOpenApiConfig.configJHApiExecution(new JHFileApiExecution()); + public JHAppApiExecution appApiExecution() { + return new JHAppApiExecution(); } @Bean - public JHJobApiExecution jobApiExecution(JHOpenApiConfig jhOpenApiConfig) { - return jhOpenApiConfig.configJHApiExecution(new JHJobApiExecution()); + public JHDataApiExecution dataApiExecution() { + return new JHDataApiExecution(); } @Bean - public JHDepartmentApiExecution departmentApiExecution(JHOpenApiConfig jhOpenApiConfig) { - return jhOpenApiConfig.configJHApiExecution(new JHDepartmentApiExecution()); + public JHFileApiExecution fileApiExecution() { + return new JHFileApiExecution(); } @Bean - public JHUserApiExecution userApiExecution(JHOpenApiConfig jhOpenApiConfig) { - return jhOpenApiConfig.configJHApiExecution(new JHUserApiExecution()); + public JHJobApiExecution jobApiExecution() { + return new JHJobApiExecution(); } + + @Bean + public JHDepartmentApiExecution departmentApiExecution() { + return new JHDepartmentApiExecution(); + } + + @Bean + public JHUserApiExecution userApiExecution() { + return new JHUserApiExecution(); + } + } diff --git a/jhinno-openapi-sdk-spring-boot-starter/src/main/java/com/jhinno/sdk/openapi/utils/JHOpenApiConfig.java b/jhinno-openapi-sdk-spring-boot-starter/src/main/java/com/jhinno/sdk/openapi/utils/JHOpenApiConfig.java deleted file mode 100644 index 7b08580..0000000 --- a/jhinno-openapi-sdk-spring-boot-starter/src/main/java/com/jhinno/sdk/openapi/utils/JHOpenApiConfig.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.jhinno.sdk.openapi.utils; - -import com.jhinno.sdk.openapi.api.JHApiExecution; -import com.jhinno.sdk.openapi.autoconfigure.JHOpenapiProperties; -import com.jhinno.sdk.openapi.client.JHApiClient; -import lombok.RequiredArgsConstructor; -import org.springframework.context.annotation.Configuration; - -@Configuration -@RequiredArgsConstructor -public class JHOpenApiConfig { - - private final JHApiClient client; - private final JHOpenapiProperties properties; - - /** - * 配置执行器 - * - * @param execution 执行器 - * @param 执行器类型 - * @return 配置的执行器 - */ - public T configJHApiExecution(T execution) { - execution.setJhApiClient(client); - execution.setForceGetToken(properties.isForceGetToken()); - execution.setAuthType(properties.getAuthType()); - execution.setAccessKey(properties.getAccessKey()); - execution.setAccessKeySecret(properties.getAccessKeySecret()); - execution.setTokenTimeout(properties.getTokenTimeout()); - execution.setTokenResidueTime(properties.getTokenResidueTime()); - execution.setUsedServerTime(properties.isUsedServerTime()); - return execution; - } - -} diff --git a/jhinno-openapi-sdk-spring-boot-starter/src/main/resources/META-INF/spring.factories b/jhinno-openapi-sdk-spring-boot-starter/src/main/resources/META-INF/spring.factories index af1c87a..b7d5802 100644 --- a/jhinno-openapi-sdk-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/jhinno-openapi-sdk-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -1,4 +1,3 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.jhinno.sdk.openapi.autoconfigure.JHOpenapiClientAutoConfigure,\ - com.jhinno.sdk.openapi.utils.JHOpenApiConfig,\ com.jhinno.sdk.openapi.autoconfigure.JHOpenapiExecutionAutoconfigure \ No newline at end of file diff --git a/jhinno-openapi-sdk-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/jhinno-openapi-sdk-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index bc5dd67..b3a4867 100644 --- a/jhinno-openapi-sdk-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/jhinno-openapi-sdk-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,3 +1,2 @@ com.jhinno.sdk.openapi.autoconfigure.JHOpenapiClientAutoConfigure -com.jhinno.sdk.openapi.utils.JHOpenApiConfig com.jhinno.sdk.openapi.autoconfigure.JHOpenapiExecutionAutoconfigure \ No newline at end of file