作业数据区SDK接口集成完成

This commit is contained in:
lqyan
2024-02-04 18:29:56 +08:00
parent fd05af58e6
commit 7906e6d473
9 changed files with 339 additions and 12 deletions

View File

@@ -17,7 +17,7 @@ public class SessionInfo {
/**
* 最后使用时间
*/
private String lastUseTime;
private Date lastUseTime;
/**
* 转移操作员权限
*/
@@ -67,7 +67,7 @@ public class SessionInfo {
/**
* 创建时间
*/
private String createDate;
private Date createDate;
/**
* 密级
*/

View File

@@ -0,0 +1,42 @@
package com.jhinno.sdk.openapi.api.data;
/**
* 作业数据请求路径
*
* @author yanlongqi
* @date 2024/2/4 17:02
*/
public class DataPathConstant {
/**
* 根据用户scope查询数据目录列表
*/
public static final String DATA_SPOOLERS_PATH = "/ws/api/spoolers";
/**
* 根据作业id查数据目录信息
*/
public static final String DATA_SPOOLER_JOB_ID_PATH = "/ws/api/spooler/{jobId}";
/**
* 根据作业id集合查询数据目录列表
*/
public static final String DATA_SPOOLERS_LIST_PATH = "/ws/api/spoolers/list";
/**
* 根据数据目录名称查询数据目录列表
*/
public static final String DATA_SPOOLERS_NAME_PATH = "/ws/api/spoolers/name";
/**
* 立即删除数据目录
*/
public static final String DATA_SPOOLERS_DELETE_ID_PATH = "/ws/api/spooler/del/{id}";
/**
* 设置过期时间删除数据目录
*/
public static final String DATA_SPOOLERS_PURGE_PATH = "/ws/api/spooler/purge";
}

View File

@@ -0,0 +1,143 @@
package com.jhinno.sdk.openapi.api.data;
import cn.hutool.core.collection.CollectionUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.jhinno.sdk.openapi.ArgsException;
import com.jhinno.sdk.openapi.CommonConstant;
import com.jhinno.sdk.openapi.ServiceException;
import com.jhinno.sdk.openapi.api.JHApiExecution;
import com.jhinno.sdk.openapi.api.ResponseResult;
import com.jhinno.sdk.openapi.client.JHApiClient;
import org.apache.commons.lang3.StringUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author yanlongqi
* @date 2024/2/4 17:09
*/
public class JHDataApiExecution extends JHApiExecution {
/**
* 获取一个执行器的实例
*
* @param jhApiClient 请求的客户端
*/
public JHDataApiExecution(JHApiClient jhApiClient) {
super(jhApiClient);
}
/**
* 根据用户scope查询数据目录列表
*
* @return 用户数据目录列表
*/
public List<SpoolerDataInfo> getSpoolersData(String username) {
return get(DataPathConstant.DATA_SPOOLERS_PATH, username, new TypeReference<ResponseResult<List<SpoolerDataInfo>>>() {
});
}
/**
* 根据作业id查作业数据目录信息
*
* @param username 用户名
* @param jobId 作业id
* @return 作业目录信息
*/
public SpoolerDataInfo getSpoolersDataById(String username, String jobId) {
if (StringUtils.isBlank(jobId)) {
throw new ArgsException("jobId不能为空");
}
String path = DataPathConstant.DATA_SPOOLER_JOB_ID_PATH.replace("{jobId}", jobId);
List<SpoolerDataInfo> list = get(path, username, new TypeReference<ResponseResult<List<SpoolerDataInfo>>>() {
});
if (CollectionUtil.isEmpty(list)) {
throw new ServiceException(path, 500, "作业数据目录信息为空!");
}
return list.get(0);
}
/**
* 根据作业id集合查询数据目录列表
*
* @param username 用户名
* @param jobIds 作业id列表
* @return 用户数据目录列表
*/
public List<SpoolerDataInfo> getSpoolersDataByIds(String username, List<String> jobIds) {
if (CollectionUtil.isEmpty(jobIds)) {
throw new ArgsException("jobIds不能为空");
}
Map<String, Object> 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<ResponseResult<List<SpoolerDataInfo>>>() {
});
}
/**
* 根据数据目录名称查询数据目录列表 (产品接口有问题)
*
* @param username 用户名
* @param dataName 数据目录名称
* @return 作业目录信息
*/
public SpoolerDataInfo getSpoolersByName(String username, String dataName) {
if (StringUtils.isBlank(dataName)) {
throw new ArgsException("dataName不能为空");
}
Map<String, Object> params = new HashMap<>(1);
params.put("name", dataName);
String path = JHApiClient.getUrl(DataPathConstant.DATA_SPOOLERS_NAME_PATH, params);
List<SpoolerDataInfo> list = get(path, username, new TypeReference<ResponseResult<List<SpoolerDataInfo>>>() {
});
if (CollectionUtil.isEmpty(list)) {
throw new ServiceException(path, 500, "作业数据目录信息为空!");
}
return list.get(0);
}
/**
* 立即删除作业数据目录
*
* @param username 用户名
* @param jobId 作业id
*/
public void deleteSpoolerData(String username, String jobId) {
if (StringUtils.isBlank(jobId)) {
throw new ArgsException("jobId不能为空");
}
String path = DataPathConstant.DATA_SPOOLERS_DELETE_ID_PATH.replace("{id}", jobId);
get(path, username, new TypeReference<ResponseResult<Object>>() {
});
}
/**
* 设置用户数据目录的过期时间,也给以通过设置过期时间来删除用户数据区
*
* @param username 用户名
* @param jobId 作业id
* @param expirationTime 过期时间
*/
public void purgeSpooler(String username, String jobId, Date expirationTime) {
if (StringUtils.isBlank(jobId)) {
throw new ArgsException("jobId不能为空");
}
if (expirationTime == null) {
throw new ArgsException("expirationTime不能为空");
}
Map<String, Object> params = new HashMap<>(2);
params.put("id", jobId);
params.put("expiration_time", expirationTime);
String path = JHApiClient.getUrl(DataPathConstant.DATA_SPOOLERS_PURGE_PATH, params);
get(path, username, new TypeReference<ResponseResult<Object>>() {
});
}
}

View File

@@ -0,0 +1,85 @@
package com.jhinno.sdk.openapi.api.data;
import lombok.Data;
import java.util.Date;
/**
* 作业数据信息
*
* @author yanlongqi
* @date 2024/2/4 17:20
*/
@Data
public class SpoolerDataInfo {
/**
* 作业名称
*/
private String jobName;
/**
* 作业用户名
*/
private String jobUser;
/**
* 提交目录
*/
private String subCwd;
/**
* 数据名称
*/
private String dataName;
/**
* 作业项目
*/
private String jobProject;
/**
* 作业路径
*/
private String dataPath;
/**
* 作业id
*/
private String jobId;
/**
* 创建时间
*/
private Date createTime;
/**
* 删除时间
*/
private Date deleteTime;
/**
* 是否自定义作业
*/
private Boolean is_custom_spooler;
/**
* 作业系统类型
*/
private String job_os_type;
/**
* 密级中文名
*/
private String confidentialCn;
/**
* 密级英文名
*/
private String confidentialEn;
/**
* 密级
*/
private String confidential;
}

View File

@@ -32,6 +32,7 @@ import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
@@ -303,6 +304,10 @@ public class JHApiClient {
urlBuilder.append(entry.getKey()).append("=");
if (value instanceof String) {
urlBuilder.append(URLEncoder.encode((String) value, "utf-8"));
}
if (value instanceof Date) {
SimpleDateFormat format = new SimpleDateFormat(DatePattern.NORM_DATETIME_PATTERN);
urlBuilder.append(URLEncoder.encode(format.format(value), "utf-8"));
} else {
urlBuilder.append(value);
}