Browse Source

修改示例

master
richie 2 years ago
parent
commit
449e0fbd47
  1. 18
      src/main/java/com/fanruan/hihidata/datasource/server/DatasourceOperation.java
  2. 2
      src/main/java/com/fanruan/hihidata/datasource/server/ProjectConstants.java
  3. 8
      src/main/java/com/fanruan/hihidata/datasource/server/ServerApplication.java
  4. 16
      src/main/java/com/fanruan/hihidata/datasource/server/http/HttpKits.java

18
src/main/java/com/fanruan/hihidata/datasource/server/DatasourceOperation.java

@ -25,7 +25,10 @@ public class DatasourceOperation {
JSONObject body = new JSONObject(); JSONObject body = new JSONObject();
body.put("status", "1"); body.put("status", "1");
HttpEntity entity = new StringEntity(body.toString(), StandardCharsets.UTF_8); HttpEntity entity = new StringEntity(body.toString(), StandardCharsets.UTF_8);
HttpKits.post(String.format("%s/api/v1/datasource/status/modify", ProjectConstants.BASE_URI), headers(), entity); 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);
} }
public void createGroup(String groupName) throws Exception { public void createGroup(String groupName) throws Exception {
@ -35,6 +38,15 @@ public class DatasourceOperation {
HttpKits.post(String.format("%s/api/v1/datasource/group/create", ProjectConstants.BASE_URI), headers(), entity); HttpKits.post(String.format("%s/api/v1/datasource/group/create", ProjectConstants.BASE_URI), headers(), entity);
} }
public String createTable(String tableName) throws Exception {
JSONObject body = new JSONObject();
body.put("tableName", tableName);
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");
}
public String createTable(String tableName, String groupName) throws Exception { public String createTable(String tableName, String groupName) throws Exception {
JSONObject body = new JSONObject(); JSONObject body = new JSONObject();
body.put("name", tableName); body.put("name", tableName);
@ -47,7 +59,9 @@ public class DatasourceOperation {
JSONObject body = new JSONObject(); JSONObject body = new JSONObject();
body.put("tableId", tableId); body.put("tableId", tableId);
HttpEntity entity = new StringEntity(body.toString(), StandardCharsets.UTF_8); HttpEntity entity = new StringEntity(body.toString(), StandardCharsets.UTF_8);
return HttpKits.post(String.format("%s/api/v1/datasource/table/upload/url", ProjectConstants.BASE_URI), headers(), entity); String res = HttpKits.post(String.format("%s/api/v1/datasource/table/upload/url", ProjectConstants.BASE_URI), headers(), entity);
JSONObject data = new JSONObject(res);
return data.getString("data");
} }
public void markAsFinish(String tableId) throws Exception { public void markAsFinish(String tableId) throws Exception {

2
src/main/java/com/fanruan/hihidata/datasource/server/ProjectConstants.java

@ -6,5 +6,5 @@ package com.fanruan.hihidata.datasource.server;
*/ */
public class ProjectConstants { public class ProjectConstants {
public static final String BASE_URI = "https://work.jiushuyun.com/decision"; public static final String BASE_URI = "https://test.jiushuyun.com/decision";
} }

8
src/main/java/com/fanruan/hihidata/datasource/server/ServerApplication.java

@ -11,13 +11,13 @@ import java.io.File;
public class ServerApplication { public class ServerApplication {
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
Authentication authentication = new Authentication(args[0], args[1]); Authentication authentication = new Authentication("ZDdjOWJhZGI5OTBjNDI3ZWE2MzAzYWYwY2UyMTI1Zjg=", "103d4522039be2d17588882b7ae5ba12");
DatasourceOperation operation = new DatasourceOperation(authentication); DatasourceOperation operation = new DatasourceOperation(authentication);
operation.open(); //operation.open();
// 创建一个分组,如果已经存在,则直接跳过 // 创建一个分组,如果已经存在,则直接跳过
operation.createGroup("TestGroup"); //operation.createGroup("TestGroup");
// 在分组下创建一个表,返回创建的表的ID,如果表已经存在,则直接返回表ID // 在分组下创建一个表,返回创建的表的ID,如果表已经存在,则直接返回表ID
String tableId = operation.createTable("HelloTable", "TestGroup"); String tableId = operation.createTable("HelloTable");
// 获取上传文件的url // 获取上传文件的url
String fileUploadUrl = operation.requestUploadUrl(tableId); String fileUploadUrl = operation.requestUploadUrl(tableId);
// 将数据文件上传 // 将数据文件上传

16
src/main/java/com/fanruan/hihidata/datasource/server/http/HttpKits.java

@ -206,6 +206,22 @@ public class HttpKits {
.build()); .build());
} }
/**
* 发起POST请求并获取返回的文本
*
* @param url 响应请求的的服务器地址
* @param headers POST请求的参数
* @return 服务器返回的文本内容
*/
public static String post(String url, Map<String, String> headers, Map<String, String> params) throws IOException {
return executeAndParse(HttpRequest
.custom()
.url(url)
.headers(headers)
.post(params)
.build());
}
/** /**
* 上传文件到指定的服务器 * 上传文件到指定的服务器
* *

Loading…
Cancel
Save