forked from github/dataease
commit
cde7bae4a6
@ -23,5 +23,7 @@ public class ApiDefinition {
|
|||||||
private int previewNum = 10;
|
private int previewNum = 10;
|
||||||
private int maxPreviewNum = 10;
|
private int maxPreviewNum = 10;
|
||||||
private int serialNumber;
|
private int serialNumber;
|
||||||
|
private boolean useJsonPath;
|
||||||
|
private String jsonPath;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,6 @@ public class ApiProvider extends Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public String execHttpRequest(ApiDefinition apiDefinition, int socketTimeout) throws Exception {
|
static public String execHttpRequest(ApiDefinition apiDefinition, int socketTimeout) throws Exception {
|
||||||
|
|
||||||
String response = "";
|
String response = "";
|
||||||
HttpClientConfig httpClientConfig = new HttpClientConfig();
|
HttpClientConfig httpClientConfig = new HttpClientConfig();
|
||||||
httpClientConfig.setSocketTimeout(socketTimeout * 1000);
|
httpClientConfig.setSocketTimeout(socketTimeout * 1000);
|
||||||
@ -135,7 +134,6 @@ public class ApiProvider extends Provider {
|
|||||||
httpClientConfig.addHeader(header.get("name").toString(), header.get("value").toString());
|
httpClientConfig.addHeader(header.get("name").toString(), header.get("value").toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apiDefinitionRequest.getAuthManager() != null
|
if (apiDefinitionRequest.getAuthManager() != null
|
||||||
&& StringUtils.isNotBlank(apiDefinitionRequest.getAuthManager().getUsername())
|
&& StringUtils.isNotBlank(apiDefinitionRequest.getAuthManager().getUsername())
|
||||||
&& StringUtils.isNotBlank(apiDefinitionRequest.getAuthManager().getPassword())
|
&& StringUtils.isNotBlank(apiDefinitionRequest.getAuthManager().getPassword())
|
||||||
@ -188,27 +186,72 @@ public class ApiProvider extends Provider {
|
|||||||
throw new Exception("该请求返回数据为空");
|
throw new Exception("该请求返回数据为空");
|
||||||
}
|
}
|
||||||
List<JSONObject> fields = new ArrayList<>();
|
List<JSONObject> fields = new ArrayList<>();
|
||||||
String rootPath;
|
if (apiDefinition.isUseJsonPath()) {
|
||||||
if (response.startsWith("[")) {
|
List<LinkedHashMap> currentData = new ArrayList<>();
|
||||||
rootPath = "$[*]";
|
Object object = JsonPath.read(response, apiDefinition.getJsonPath());
|
||||||
JSONArray jsonArray = JSONObject.parseArray(response);
|
if (object instanceof List) {
|
||||||
for (Object o : jsonArray) {
|
currentData = (List<LinkedHashMap>) object;
|
||||||
handleStr(apiDefinition, o.toString(), fields, rootPath);
|
} else {
|
||||||
|
currentData.add((LinkedHashMap) object);
|
||||||
}
|
}
|
||||||
|
for (LinkedHashMap data : currentData) {
|
||||||
|
int i = 0;
|
||||||
|
if (i >= apiDefinition.getPreviewNum()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i == 0) {
|
||||||
|
for (Object o : data.keySet()) {
|
||||||
|
JSONObject field = new JSONObject();
|
||||||
|
field.put("originName", o.toString());
|
||||||
|
field.put("name", o.toString());
|
||||||
|
field.put("type", "STRING");
|
||||||
|
field.put("checked", true);
|
||||||
|
field.put("size", 65535);
|
||||||
|
field.put("deExtractType", 0);
|
||||||
|
field.put("deType", 0);
|
||||||
|
field.put("extField", 0);
|
||||||
|
fields.add(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (JSONObject field : fields) {
|
||||||
|
JSONArray array = field.getJSONArray("value");
|
||||||
|
if (array != null) {
|
||||||
|
array.add(Optional.ofNullable(data.get(field.getString("originName"))).orElse("").toString().replaceAll("\n", " ").replaceAll("\r", " "));
|
||||||
|
} else {
|
||||||
|
array = new JSONArray();
|
||||||
|
array.add(Optional.ofNullable(data.get(field.getString("originName"))).orElse("").toString().replaceAll("\n", " ").replaceAll("\r", " "));
|
||||||
|
}
|
||||||
|
field.put("value", array);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apiDefinition.setJsonFields(fields);
|
||||||
|
return apiDefinition;
|
||||||
} else {
|
} else {
|
||||||
rootPath = "$";
|
|
||||||
handleStr(apiDefinition, response, fields, rootPath);
|
String rootPath;
|
||||||
}
|
if (response.startsWith("[")) {
|
||||||
for (JSONObject field : fields) {
|
rootPath = "$[*]";
|
||||||
if (field.containsKey("children") && CollectionUtils.isNotEmpty(field.getJSONArray("children"))) {
|
JSONArray jsonArray = JSONObject.parseArray(response);
|
||||||
field.put("disabled", false);
|
for (Object o : jsonArray) {
|
||||||
|
handleStr(apiDefinition, o.toString(), fields, rootPath);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rootPath = "$";
|
||||||
|
handleStr(apiDefinition, response, fields, rootPath);
|
||||||
}
|
}
|
||||||
if (field.containsKey("children") && CollectionUtils.isEmpty(field.getJSONArray("children"))) {
|
for (JSONObject field : fields) {
|
||||||
field.put("disabled", true);
|
if (field.containsKey("children") && CollectionUtils.isNotEmpty(field.getJSONArray("children"))) {
|
||||||
|
field.put("disabled", false);
|
||||||
|
}
|
||||||
|
if (field.containsKey("children") && CollectionUtils.isEmpty(field.getJSONArray("children"))) {
|
||||||
|
field.put("disabled", true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
apiDefinition.setJsonFields(fields);
|
||||||
|
return apiDefinition;
|
||||||
}
|
}
|
||||||
apiDefinition.setJsonFields(fields);
|
|
||||||
return apiDefinition;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -362,7 +405,7 @@ public class ApiProvider extends Provider {
|
|||||||
|
|
||||||
private List<String[]> fetchResult(String result, ApiDefinition apiDefinition) {
|
private List<String[]> fetchResult(String result, ApiDefinition apiDefinition) {
|
||||||
List<String[]> dataList = new LinkedList<>();
|
List<String[]> dataList = new LinkedList<>();
|
||||||
if (StringUtils.isNotEmpty(apiDefinition.getDataPath()) && CollectionUtils.isEmpty(apiDefinition.getJsonFields())) {
|
if(apiDefinition.isUseJsonPath()){
|
||||||
List<LinkedHashMap> currentData = new ArrayList<>();
|
List<LinkedHashMap> currentData = new ArrayList<>();
|
||||||
Object object = JsonPath.read(result, apiDefinition.getDataPath());
|
Object object = JsonPath.read(result, apiDefinition.getDataPath());
|
||||||
if (object instanceof List) {
|
if (object instanceof List) {
|
||||||
@ -379,30 +422,49 @@ public class ApiProvider extends Provider {
|
|||||||
}
|
}
|
||||||
dataList.add(row);
|
dataList.add(row);
|
||||||
}
|
}
|
||||||
} else {
|
}else {
|
||||||
List<String> jsonPaths = apiDefinition.getFields().stream().map(DatasetTableFieldDTO::getJsonPath).collect(Collectors.toList());
|
if (StringUtils.isNotEmpty(apiDefinition.getDataPath()) && CollectionUtils.isEmpty(apiDefinition.getJsonFields())) {
|
||||||
Long maxLength = 0l;
|
List<LinkedHashMap> currentData = new ArrayList<>();
|
||||||
List<List<String>> columnDataList = new ArrayList<>();
|
Object object = JsonPath.read(result, apiDefinition.getDataPath());
|
||||||
for (int i = 0; i < jsonPaths.size(); i++) {
|
if (object instanceof List) {
|
||||||
List<String> data = new ArrayList<>();
|
currentData = (List<LinkedHashMap>) object;
|
||||||
Object object = JsonPath.read(result, jsonPaths.get(i));
|
|
||||||
if (object instanceof List && jsonPaths.get(i).contains("[*]")) {
|
|
||||||
data = (List<String>) object;
|
|
||||||
} else {
|
} else {
|
||||||
if (object != null) {
|
currentData.add((LinkedHashMap) object);
|
||||||
data.add(object.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
maxLength = maxLength > data.size() ? maxLength : data.size();
|
for (LinkedHashMap data : currentData) {
|
||||||
columnDataList.add(data);
|
String[] row = new String[apiDefinition.getFields().size()];
|
||||||
}
|
int i = 0;
|
||||||
for (int i = 0; i < maxLength; i++) {
|
for (DatasetTableFieldDTO field : apiDefinition.getFields()) {
|
||||||
String[] row = new String[apiDefinition.getFields().size()];
|
row[i] = Optional.ofNullable(data.get(field.getOriginName())).orElse("").toString().replaceAll("\n", " ").replaceAll("\r", " ");
|
||||||
dataList.add(row);
|
i++;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < columnDataList.size(); i++) {
|
dataList.add(row);
|
||||||
for (int j = 0; j < columnDataList.get(i).size(); j++) {
|
}
|
||||||
dataList.get(j)[i] = Optional.ofNullable(String.valueOf(columnDataList.get(i).get(j))).orElse("").replaceAll("\n", " ").replaceAll("\r", " ");
|
} else {
|
||||||
|
List<String> jsonPaths = apiDefinition.getFields().stream().map(DatasetTableFieldDTO::getJsonPath).collect(Collectors.toList());
|
||||||
|
Long maxLength = 0l;
|
||||||
|
List<List<String>> columnDataList = new ArrayList<>();
|
||||||
|
for (int i = 0; i < jsonPaths.size(); i++) {
|
||||||
|
List<String> data = new ArrayList<>();
|
||||||
|
Object object = JsonPath.read(result, jsonPaths.get(i));
|
||||||
|
if (object instanceof List && jsonPaths.get(i).contains("[*]")) {
|
||||||
|
data = (List<String>) object;
|
||||||
|
} else {
|
||||||
|
if (object != null) {
|
||||||
|
data.add(object.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maxLength = maxLength > data.size() ? maxLength : data.size();
|
||||||
|
columnDataList.add(data);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < maxLength; i++) {
|
||||||
|
String[] row = new String[apiDefinition.getFields().size()];
|
||||||
|
dataList.add(row);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < columnDataList.size(); i++) {
|
||||||
|
for (int j = 0; j < columnDataList.get(i).size(); j++) {
|
||||||
|
dataList.get(j)[i] = Optional.ofNullable(String.valueOf(columnDataList.get(i).get(j))).orElse("").replaceAll("\n", " ").replaceAll("\r", " ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2431,7 +2431,7 @@ public class DataSetTableService {
|
|||||||
int num = 1;
|
int num = 1;
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
if (num > 100) {
|
if (num > 1000) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
data.add(Arrays.asList(line.split(",")));
|
data.add(Arrays.asList(line.split(",")));
|
||||||
|
@ -1894,7 +1894,9 @@ export default {
|
|||||||
base_info: 'Basic information',
|
base_info: 'Basic information',
|
||||||
column_info: 'Data structure',
|
column_info: 'Data structure',
|
||||||
request: 'Request',
|
request: 'Request',
|
||||||
|
isUseJsonPath: 'Specify JsonPath or not',
|
||||||
path_all_info: 'Please fill in the full address',
|
path_all_info: 'Please fill in the full address',
|
||||||
|
jsonpath_info: 'Please fill in JsonPath',
|
||||||
req_param: 'Request parameters',
|
req_param: 'Request parameters',
|
||||||
headers: 'Request header',
|
headers: 'Request header',
|
||||||
key: 'Key',
|
key: 'Key',
|
||||||
|
@ -1888,7 +1888,9 @@ export default {
|
|||||||
base_info: '基礎信息',
|
base_info: '基礎信息',
|
||||||
column_info: '資料結構',
|
column_info: '資料結構',
|
||||||
request: '請求',
|
request: '請求',
|
||||||
|
isUseJsonPath: '是否指定JsonPath',
|
||||||
path_all_info: '請輸入完整地址',
|
path_all_info: '請輸入完整地址',
|
||||||
|
jsonpath_info: '請輸入JsonPath',
|
||||||
req_param: '請求參數',
|
req_param: '請求參數',
|
||||||
headers: '請求頭',
|
headers: '請求頭',
|
||||||
key: '鍵',
|
key: '鍵',
|
||||||
|
@ -1887,7 +1887,9 @@ export default {
|
|||||||
base_info: '基础信息',
|
base_info: '基础信息',
|
||||||
column_info: '数据结构',
|
column_info: '数据结构',
|
||||||
request: '请求',
|
request: '请求',
|
||||||
|
isUseJsonPath: '是否指定JsonPath',
|
||||||
path_all_info: '请填入完整地址',
|
path_all_info: '请填入完整地址',
|
||||||
|
jsonpath_info: '请填入JsonPath',
|
||||||
req_param: '请求参数',
|
req_param: '请求参数',
|
||||||
headers: '请求头',
|
headers: '请求头',
|
||||||
key: '键',
|
key: '键',
|
||||||
|
@ -535,6 +535,32 @@
|
|||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<el-form-item
|
||||||
|
:label="$t('datasource.isUseJsonPath')"
|
||||||
|
prop="url"
|
||||||
|
>
|
||||||
|
<el-input
|
||||||
|
v-model="apiItem.jsonPath"
|
||||||
|
:placeholder="$t('datasource.jsonpath_info')"
|
||||||
|
class="input-with-select"
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
<el-select
|
||||||
|
slot="prepend"
|
||||||
|
v-model="apiItem.useJsonPath"
|
||||||
|
style="width: 100px"
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in isUseJsonPath"
|
||||||
|
:key="item.id"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.id"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-input>
|
||||||
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
</el-row>
|
</el-row>
|
||||||
<el-row v-show="active === 2">
|
<el-row v-show="active === 2">
|
||||||
@ -567,7 +593,7 @@
|
|||||||
<el-checkbox
|
<el-checkbox
|
||||||
:key="scope.row.jsonPath"
|
:key="scope.row.jsonPath"
|
||||||
v-model="scope.row.checked"
|
v-model="scope.row.checked"
|
||||||
:disabled="scope.row.disabled"
|
:disabled="scope.row.disabled || apiItem.useJsonPath"
|
||||||
@change="handleCheckAllChange(scope.row)"
|
@change="handleCheckAllChange(scope.row)"
|
||||||
>
|
>
|
||||||
{{ scope.row.originName }}
|
{{ scope.row.originName }}
|
||||||
@ -973,12 +999,18 @@ export default {
|
|||||||
originName: 'comments',
|
originName: 'comments',
|
||||||
deExtractType: 0
|
deExtractType: 0
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
useJsonPath: false,
|
||||||
|
jsonPath: ''
|
||||||
},
|
},
|
||||||
reqOptions: [
|
reqOptions: [
|
||||||
{ id: 'GET', label: 'GET' },
|
{ id: 'GET', label: 'GET' },
|
||||||
{ id: 'POST', label: 'POST' }
|
{ id: 'POST', label: 'POST' }
|
||||||
],
|
],
|
||||||
|
isUseJsonPath: [
|
||||||
|
{ id: true, label: this.$t('commons.yes') },
|
||||||
|
{ id: false, label: this.$t('commons.no') }
|
||||||
|
],
|
||||||
loading: false,
|
loading: false,
|
||||||
responseData: { type: 'HTTP', responseResult: {}, subRequestResults: [] },
|
responseData: { type: 'HTTP', responseResult: {}, subRequestResults: [] },
|
||||||
api_step2_active_name: 'first',
|
api_step2_active_name: 'first',
|
||||||
|
@ -1018,6 +1018,7 @@ export default {
|
|||||||
delete item.status
|
delete item.status
|
||||||
})
|
})
|
||||||
form.configuration = Base64.encode(JSON.stringify(form.apiConfiguration))
|
form.configuration = Base64.encode(JSON.stringify(form.apiConfiguration))
|
||||||
|
form.apiConfiguration = []
|
||||||
} else {
|
} else {
|
||||||
form.configuration = Base64.encode(JSON.stringify(form.configuration))
|
form.configuration = Base64.encode(JSON.stringify(form.configuration))
|
||||||
}
|
}
|
||||||
@ -1156,6 +1157,7 @@ export default {
|
|||||||
const data = JSON.parse(JSON.stringify(this.form))
|
const data = JSON.parse(JSON.stringify(this.form))
|
||||||
if (data.type === 'api') {
|
if (data.type === 'api') {
|
||||||
data.configuration = Base64.encode(JSON.stringify(data.apiConfiguration))
|
data.configuration = Base64.encode(JSON.stringify(data.apiConfiguration))
|
||||||
|
data.apiConfiguration = []
|
||||||
} else {
|
} else {
|
||||||
data.configuration = Base64.encode(JSON.stringify(data.configuration))
|
data.configuration = Base64.encode(JSON.stringify(data.configuration))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user