|
|
|
@ -3,6 +3,7 @@ package com.fanruan.hihidata.datasource.server;
|
|
|
|
|
import com.fanruan.hihidata.datasource.server.http.HttpKits; |
|
|
|
|
import org.apache.http.HttpEntity; |
|
|
|
|
import org.apache.http.entity.StringEntity; |
|
|
|
|
import org.json.JSONArray; |
|
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
@ -10,6 +11,7 @@ import java.util.HashMap;
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* API数据源所有操作的示例集合,只需要传入授权参数即可 |
|
|
|
|
* @author richie |
|
|
|
|
* Created by richie on 2022/9/16 |
|
|
|
|
*/ |
|
|
|
@ -21,23 +23,91 @@ public class DatasourceOperation {
|
|
|
|
|
this.auth = auth; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 开启或者关闭API数据源入口 |
|
|
|
|
* @throws Exception 操作失败则抛出此异常 |
|
|
|
|
*/ |
|
|
|
|
public void open() throws Exception { |
|
|
|
|
JSONObject body = new JSONObject(); |
|
|
|
|
body.put("status", "1"); |
|
|
|
|
HttpEntity entity = new StringEntity(body.toString(), StandardCharsets.UTF_8); |
|
|
|
|
HttpKits.post(String.format("%s/api/v1/datasource/status/modify", ProjectConstants.BASE_URI), headers(), entity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 查看当前API数据源的开关状态 |
|
|
|
|
* @return API数据源处于开启状态,则返回"1",否则返回"0" |
|
|
|
|
* @throws Exception 操作失败则抛出此异常 |
|
|
|
|
*/ |
|
|
|
|
public String status() throws Exception { |
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
String res = HttpKits.post(String.format("%s/api/v1/datasource/status", ProjectConstants.BASE_URI), headers(), params); |
|
|
|
|
JSONObject data = new JSONObject(res); |
|
|
|
|
return data.getString("data"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 在API数据源下创建一个分组 |
|
|
|
|
* @param groupName 分组名 |
|
|
|
|
* @return 该分组的Id |
|
|
|
|
* @throws Exception 操作失败则抛出此异常 |
|
|
|
|
*/ |
|
|
|
|
public String createGroup(String groupName) throws Exception { |
|
|
|
|
JSONObject body = new JSONObject(); |
|
|
|
|
body.put("groupName", groupName); |
|
|
|
|
HttpEntity entity = new StringEntity(body.toString(), StandardCharsets.UTF_8); |
|
|
|
|
String res = HttpKits.post(String.format("%s/api/v1/datasource/group/create", ProjectConstants.BASE_URI), headers(), entity); |
|
|
|
|
JSONObject data = new JSONObject(res); |
|
|
|
|
return data.getString("data"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 修改分组的名字 |
|
|
|
|
* @param groupId 分组Id |
|
|
|
|
* @param newGroupName 新的分组名字 |
|
|
|
|
* @throws Exception 操作失败则抛出此异常 |
|
|
|
|
*/ |
|
|
|
|
public void modifyGroup(String groupId, String newGroupName) throws Exception { |
|
|
|
|
JSONObject body = new JSONObject(); |
|
|
|
|
body.put("groupId", groupId); |
|
|
|
|
body.put("groupName", newGroupName); |
|
|
|
|
HttpEntity entity = new StringEntity(body.toString(), StandardCharsets.UTF_8); |
|
|
|
|
HttpKits.post(String.format("%s/api/v1/datasource/group/modify", ProjectConstants.BASE_URI), headers(), entity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 列出所有的分组 |
|
|
|
|
* @return 以JSON数组的形式输出所有分组的信息的集合 |
|
|
|
|
* @throws Exception 操作失败则抛出此异常 |
|
|
|
|
*/ |
|
|
|
|
public JSONArray listAllGroup() throws Exception { |
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
params.put("status", "1"); |
|
|
|
|
String r = HttpKits.post(String.format("%s/api/v1/datasource/status/modify", ProjectConstants.BASE_URI), headers(), params); |
|
|
|
|
System.out.println("result=" + r); |
|
|
|
|
String res = HttpKits.post(String.format("%s/api/v1/datasource/group/list", ProjectConstants.BASE_URI), headers(), params); |
|
|
|
|
JSONObject data = new JSONObject(res); |
|
|
|
|
return data.getJSONArray("data"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void createGroup(String groupName) throws Exception { |
|
|
|
|
/** |
|
|
|
|
* 列出指定分组下所有的数据源表 |
|
|
|
|
* @param groupId 分组Id |
|
|
|
|
* @return 分组下的所有数据源表组成的一个JSON数组 |
|
|
|
|
* @throws Exception 操作失败则抛出此异常 |
|
|
|
|
*/ |
|
|
|
|
public JSONArray listTablesOfGroup(String groupId) throws Exception { |
|
|
|
|
JSONObject body = new JSONObject(); |
|
|
|
|
body.put("name", groupName); |
|
|
|
|
body.put("groupId", groupId); |
|
|
|
|
HttpEntity entity = new StringEntity(body.toString(), StandardCharsets.UTF_8); |
|
|
|
|
HttpKits.post(String.format("%s/api/v1/datasource/group/create", ProjectConstants.BASE_URI), headers(), entity); |
|
|
|
|
String res = HttpKits.post(String.format("%s/api/v1/datasource/group/table/list", ProjectConstants.BASE_URI), headers(), entity); |
|
|
|
|
JSONObject data = new JSONObject(res); |
|
|
|
|
return data.getJSONArray("data"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 在默认分组下创建一个数据源表 |
|
|
|
|
* @param tableName 数据源表名 |
|
|
|
|
* @return 数据源表Id |
|
|
|
|
* @throws Exception 操作失败则抛出此异常 |
|
|
|
|
*/ |
|
|
|
|
public String createTable(String tableName) throws Exception { |
|
|
|
|
JSONObject body = new JSONObject(); |
|
|
|
|
body.put("tableName", tableName); |
|
|
|
@ -47,14 +117,43 @@ public class DatasourceOperation {
|
|
|
|
|
return data.getString("data"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String createTable(String tableName, String groupName) throws Exception { |
|
|
|
|
/** |
|
|
|
|
* 在指定的分组下创建 一个数据源表 |
|
|
|
|
* @param tableName 数据源表名 |
|
|
|
|
* @param groupId 分组Id |
|
|
|
|
* @return 数据源表Id |
|
|
|
|
* @throws Exception 操作失败则抛出此异常 |
|
|
|
|
*/ |
|
|
|
|
public String createTable(String tableName, String groupId) throws Exception { |
|
|
|
|
JSONObject body = new JSONObject(); |
|
|
|
|
body.put("tableName", tableName); |
|
|
|
|
body.put("groupId", groupId); |
|
|
|
|
HttpEntity entity = new StringEntity(body.toString(), StandardCharsets.UTF_8); |
|
|
|
|
String res = HttpKits.post(String.format("%s/api/v1/datasource/table/create", ProjectConstants.BASE_URI), headers(), entity); |
|
|
|
|
JSONObject data = new JSONObject(res); |
|
|
|
|
return data.getString("data"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 修改已有的数据源表的名字 |
|
|
|
|
* @param tableId 数据源表Id |
|
|
|
|
* @param newTableName 新的数据源表名字 |
|
|
|
|
* @throws Exception 操作失败则抛出此异常 |
|
|
|
|
*/ |
|
|
|
|
public void modifyTable(String tableId, String newTableName) throws Exception { |
|
|
|
|
JSONObject body = new JSONObject(); |
|
|
|
|
body.put("name", tableName); |
|
|
|
|
body.put("group", groupName); |
|
|
|
|
body.put("tableId", tableId); |
|
|
|
|
body.put("tableName", newTableName); |
|
|
|
|
HttpEntity entity = new StringEntity(body.toString(), StandardCharsets.UTF_8); |
|
|
|
|
return HttpKits.post(String.format("%s/api/v1/datasource/table/create", ProjectConstants.BASE_URI), headers(), entity); |
|
|
|
|
HttpKits.post(String.format("%s/api/v1/datasource/table/modify", ProjectConstants.BASE_URI), headers(), entity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 生成指定的数据源表数据上传的地址 |
|
|
|
|
* @param tableId 数据源表Id |
|
|
|
|
* @return 上传数据的地址 |
|
|
|
|
* @throws Exception 操作失败则抛出此异常 |
|
|
|
|
*/ |
|
|
|
|
public String requestUploadUrl(String tableId) throws Exception { |
|
|
|
|
JSONObject body = new JSONObject(); |
|
|
|
|
body.put("tableId", tableId); |
|
|
|
@ -64,6 +163,11 @@ public class DatasourceOperation {
|
|
|
|
|
return data.getString("data"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 标记数据源表的数据上传已完成 |
|
|
|
|
* @param tableId 数据源表Id |
|
|
|
|
* @throws Exception 操作失败则抛出此异常 |
|
|
|
|
*/ |
|
|
|
|
public void markAsFinish(String tableId) throws Exception { |
|
|
|
|
JSONObject body = new JSONObject(); |
|
|
|
|
body.put("tableId", tableId); |
|
|
|
@ -71,6 +175,11 @@ public class DatasourceOperation {
|
|
|
|
|
HttpKits.post(String.format("%s/api/v1/datasource/table/upload/finish", ProjectConstants.BASE_URI), headers(), entity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 删除数据源表 |
|
|
|
|
* @param tableId 数据源表Id |
|
|
|
|
* @throws Exception 操作失败则抛出此异常 |
|
|
|
|
*/ |
|
|
|
|
public void deleteTable(String tableId) throws Exception { |
|
|
|
|
JSONObject body = new JSONObject(); |
|
|
|
|
body.put("tableId", tableId); |
|
|
|
@ -78,6 +187,10 @@ public class DatasourceOperation {
|
|
|
|
|
HttpKits.post(String.format("%s/api/v1/datasource/table/delete", ProjectConstants.BASE_URI), headers(), entity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 删除API数据源下的所有分组和表 |
|
|
|
|
* @throws Exception 操作失败则抛出此异常 |
|
|
|
|
*/ |
|
|
|
|
public void reset() throws Exception { |
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
HttpKits.post(String.format("%s/api/v1/datasource/reset", ProjectConstants.BASE_URI), headers(), params); |
|
|
|
|