mirror of
https://github.com/yanlongqi/jhinno-openapi-java-sdk.git
synced 2026-03-22 06:15:10 +08:00
文件重命名和删除文件
This commit is contained in:
@@ -12,6 +12,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 定义一个请求的执行器,
|
||||
@@ -49,7 +50,7 @@ public class JHApiExecution {
|
||||
/**
|
||||
* 用户令牌的缓存
|
||||
*/
|
||||
private static final Map<String, TokenInfo> TOKEN_INFO_MAP = new HashMap<>(10);
|
||||
private static final Map<String, TokenInfo> TOKEN_INFO_MAP = new ConcurrentHashMap<>(20);
|
||||
|
||||
/**
|
||||
* 设置在JHApiClient实例的实例
|
||||
@@ -264,4 +265,47 @@ public class JHApiExecution {
|
||||
put(path, username, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发起一个DELETE请求,有数据返回
|
||||
*
|
||||
* @param path 请求路径
|
||||
* @param username 用户名
|
||||
* @param type 响应类型
|
||||
* @param <R> 响应数据类型
|
||||
* @return 响应数据
|
||||
*/
|
||||
public <R> R delete(String path, String username, TypeReference<ResponseResult<R>> type) {
|
||||
ResponseResult<R> result = jhApiClient.delete(path, getHeaders(username), type);
|
||||
if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) {
|
||||
throw new ServiceException(path, result.getCode(), result.getMessage());
|
||||
}
|
||||
return result.getData();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发起一个DELETE请求,没有数据返回
|
||||
*
|
||||
* @param path 请求路劲
|
||||
* @param username 用户名
|
||||
*/
|
||||
public void delete(String path, String username) {
|
||||
ResponseResult<?> result = jhApiClient.delete(path, getHeaders(username), new TypeReference<ResponseResult<?>>() {
|
||||
});
|
||||
if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) {
|
||||
throw new ServiceException(path, result.getCode(), result.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退出用户的登录,释放许可
|
||||
*
|
||||
* @param username 用户名
|
||||
*/
|
||||
public void logout(String username) {
|
||||
delete(AuthPathConstant.AUTH_LOGOUT, username);
|
||||
TOKEN_INFO_MAP.remove(username);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文件接口执行器
|
||||
*
|
||||
* @author yanlongqi
|
||||
* @date 2024/2/4 17:09
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.jhinno.sdk.openapi.api.file;
|
||||
|
||||
/**
|
||||
* 文件请求路径
|
||||
*
|
||||
* @author yanlongqi
|
||||
* @date 2024/2/4 18:59
|
||||
*/
|
||||
public class FilePathConstant {
|
||||
|
||||
|
||||
/**
|
||||
* 重命名文件
|
||||
*/
|
||||
public static final String FILE_RENAME_PATH = "/ws/api/files/rename";
|
||||
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*/
|
||||
public static final String FILE_DELETE_PATH = "/ws/api/files/delete";
|
||||
|
||||
|
||||
/**
|
||||
* 拷贝文件
|
||||
*/
|
||||
public static final String FILE_COPY_PATH = "/ws/api/files/copy";
|
||||
|
||||
|
||||
/**
|
||||
* 获取文件列表
|
||||
*/
|
||||
public static final String FILE_LIST_PATH = "/ws/api/files";
|
||||
|
||||
/**
|
||||
* 创建文件夹
|
||||
*/
|
||||
public static final String FILE_MKDIR_PATH = "/ws/api/files/mkdir";
|
||||
|
||||
/**
|
||||
* 创建文件
|
||||
*/
|
||||
public static final String FILE_MKFILE_PATH = "/ws/api/files/mkfile";
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*/
|
||||
public static final String FILE_UPLOAD_PATH = "/ws/api/files/upload";
|
||||
|
||||
|
||||
/**
|
||||
* 文件下载
|
||||
*/
|
||||
public static final String FILE_DOWNLOAD_PATH = "/ws/api/files/download";
|
||||
|
||||
|
||||
/**
|
||||
* 压缩文件
|
||||
*/
|
||||
public static final String FILE_COMPRESS_PATH = "/ws/api/files/compress";
|
||||
|
||||
/**
|
||||
* 解压文件
|
||||
*/
|
||||
public static final String FILE_UNCOMPRESS_PATH = "/ws/api/files/uncompress";
|
||||
|
||||
/**
|
||||
* 浏览文件
|
||||
*/
|
||||
public static final String FILE_BROWSE_PATH = "/ws/api/browseFile";
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.jhinno.sdk.openapi.api.file;
|
||||
|
||||
import com.jhinno.sdk.openapi.ArgsException;
|
||||
import com.jhinno.sdk.openapi.api.JHApiExecution;
|
||||
import com.jhinno.sdk.openapi.client.JHApiClient;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author yanlongqi
|
||||
* @date 2024/2/4 18:58
|
||||
*/
|
||||
public class JHFileApiExecution extends JHApiExecution {
|
||||
|
||||
public JHFileApiExecution(JHApiClient jhApiClient) {
|
||||
super(jhApiClient);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重命名文件
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param sourceFileName 源文件
|
||||
* @param targetName 目标文件
|
||||
*/
|
||||
public void renameFile(String username, String sourceFileName, String targetName) {
|
||||
if (StringUtils.isBlank(sourceFileName)) {
|
||||
throw new ArgsException("sourceFileName不能为空!");
|
||||
}
|
||||
if (StringUtils.isBlank(targetName)) {
|
||||
throw new ArgsException("targetName不能为空!");
|
||||
}
|
||||
Map<String, Object> body = new HashMap<>(2);
|
||||
body.put("oldFileName", sourceFileName);
|
||||
body.put("newFileName", targetName);
|
||||
put(FilePathConstant.FILE_RENAME_PATH, username, body);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param fileName 文件路径
|
||||
*/
|
||||
public void deleteFile(String username, String fileName) {
|
||||
if (StringUtils.isBlank(fileName)) {
|
||||
throw new ArgsException("fileName不能为空!");
|
||||
}
|
||||
Map<String, Object> params = new HashMap<>(1);
|
||||
params.put("fileName", fileName);
|
||||
String path = JHApiClient.getUrl(FilePathConstant.FILE_DELETE_PATH, params);
|
||||
delete(path, username);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,14 +12,19 @@ import org.junit.Test;
|
||||
*/
|
||||
public class AuthApiTest {
|
||||
|
||||
JHAppApiExecution jhAppApiExecution = new JHAppApiExecution(JHClientConfig.client);
|
||||
|
||||
/**
|
||||
* 测试获取token
|
||||
*/
|
||||
@Test
|
||||
public void testGetToken() {
|
||||
JHAppApiExecution jhAppApiExecution = new JHAppApiExecution(JHClientConfig.client);
|
||||
String token = jhAppApiExecution.getToken("jhadmin");
|
||||
String token = jhAppApiExecution.getToken("lqyan");
|
||||
System.out.println("token:" + token);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogout(){
|
||||
jhAppApiExecution.logout("lqyan");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.jhinno.sdk.openapi.test.JHClientConfig;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author yanlongqi
|
||||
|
||||
Reference in New Issue
Block a user