forked from github/dataease
commit
dafba5d930
@ -3,7 +3,10 @@ package io.dataease.controller.datasource;
|
||||
|
||||
import io.dataease.auth.annotation.DeLog;
|
||||
import io.dataease.commons.constants.SysLogConstants;
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.commons.utils.AuthUtils;
|
||||
import io.dataease.dto.DriverDTO;
|
||||
import io.dataease.i18n.Translator;
|
||||
import io.dataease.plugins.common.base.domain.DeDriver;
|
||||
import io.dataease.plugins.common.base.domain.DeDriverDetails;
|
||||
import io.dataease.service.datasource.DriverService;
|
||||
@ -31,6 +34,7 @@ public class DriverMgmController {
|
||||
@ApiOperation("驱动列表")
|
||||
@PostMapping("/list")
|
||||
public List<DriverDTO> listDeDriver() throws Exception{
|
||||
checkPermission();
|
||||
return driverService.list();
|
||||
}
|
||||
|
||||
@ -45,6 +49,7 @@ public class DriverMgmController {
|
||||
value = "id"
|
||||
)
|
||||
public void delete(@RequestBody DeDriver deDriver) throws Exception{
|
||||
checkPermission();
|
||||
driverService.delete(deDriver);
|
||||
}
|
||||
|
||||
@ -52,6 +57,7 @@ public class DriverMgmController {
|
||||
@ApiOperation("驱动列表")
|
||||
@GetMapping("/list/{type}")
|
||||
public List<DriverDTO> listDeDriver(@PathVariable String type) throws Exception{
|
||||
checkPermission();
|
||||
return listDeDriver().stream().filter(driverDTO -> driverDTO.getType().equalsIgnoreCase(type)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@ -66,6 +72,7 @@ public class DriverMgmController {
|
||||
value = "id"
|
||||
)
|
||||
public DeDriver save(@RequestBody DeDriver deDriver) throws Exception{
|
||||
checkPermission();
|
||||
return driverService.save(deDriver);
|
||||
}
|
||||
|
||||
@ -79,6 +86,7 @@ public class DriverMgmController {
|
||||
value = "id"
|
||||
)
|
||||
public DeDriver update(@RequestBody DeDriver deDriver) throws Exception{
|
||||
checkPermission();
|
||||
return driverService.update(deDriver);
|
||||
}
|
||||
|
||||
@ -86,6 +94,7 @@ public class DriverMgmController {
|
||||
@ApiOperation("驱动文件列表")
|
||||
@GetMapping("/listDriverDetails/{id}")
|
||||
public List<DeDriverDetails> listDriverDetails(@PathVariable String id) throws Exception{
|
||||
checkPermission();
|
||||
return driverService.listDriverDetails(id);
|
||||
}
|
||||
|
||||
@ -93,6 +102,7 @@ public class DriverMgmController {
|
||||
@ApiOperation("删除驱动文件")
|
||||
@PostMapping("/deleteDriverFile")
|
||||
public void deleteDriverFile(@RequestBody DeDriverDetails deDriverDetails) throws Exception{
|
||||
checkPermission();
|
||||
driverService.deleteDriverFile(deDriverDetails.getId());
|
||||
}
|
||||
|
||||
@ -104,9 +114,15 @@ public class DriverMgmController {
|
||||
@ApiImplicitParam(name = "id", value = "驱动D", required = true, dataType = "String")
|
||||
})
|
||||
public DeDriverDetails excelUpload(@RequestParam("id") String id, @RequestParam("file") MultipartFile file) throws Exception {
|
||||
checkPermission();
|
||||
return driverService.saveJar(file, id);
|
||||
}
|
||||
|
||||
|
||||
private void checkPermission()throws Exception{
|
||||
if(!AuthUtils.getUser().getIsAdmin()){
|
||||
DEException.throwException(Translator.get("I18N_NO_DRIVER_PERMISSION"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ package io.dataease.provider.datasource;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
@ -40,7 +41,7 @@ public class ApiProvider extends Provider {
|
||||
@Override
|
||||
public List<String[]> getData(DatasourceRequest datasourceRequest) throws Exception {
|
||||
ApiDefinition apiDefinition = checkApiDefinition(datasourceRequest);
|
||||
String response = execHttpRequest(apiDefinition, apiDefinition.getApiQueryTimeout() == null || apiDefinition.getApiQueryTimeout()<=0 ? 30 : apiDefinition.getApiQueryTimeout());
|
||||
String response = execHttpRequest(apiDefinition, apiDefinition.getApiQueryTimeout() == null || apiDefinition.getApiQueryTimeout() <= 0 ? 30 : apiDefinition.getApiQueryTimeout());
|
||||
return fetchResult(response, apiDefinition);
|
||||
}
|
||||
|
||||
@ -68,7 +69,7 @@ public class ApiProvider extends Provider {
|
||||
List<String[]> dataList = new ArrayList<>();
|
||||
List<TableField> fieldList = new ArrayList<>();
|
||||
ApiDefinition apiDefinition = checkApiDefinition(datasourceRequest);
|
||||
String response = execHttpRequest(apiDefinition, apiDefinition.getApiQueryTimeout() == null || apiDefinition.getApiQueryTimeout()<=0 ? 30 : apiDefinition.getApiQueryTimeout());
|
||||
String response = execHttpRequest(apiDefinition, apiDefinition.getApiQueryTimeout() == null || apiDefinition.getApiQueryTimeout() <= 0 ? 30 : apiDefinition.getApiQueryTimeout());
|
||||
|
||||
fieldList = getTableFields(apiDefinition);
|
||||
result.put("fieldList", fieldList);
|
||||
@ -143,11 +144,11 @@ public class ApiProvider extends Provider {
|
||||
case "GET":
|
||||
List<String> params = new ArrayList<>();
|
||||
for (Map<String, String> argument : apiDefinition.getRequest().getArguments()) {
|
||||
if(StringUtils.isNotEmpty(argument.get("name")) && StringUtils.isNotEmpty(argument.get("value"))){
|
||||
if (StringUtils.isNotEmpty(argument.get("name")) && StringUtils.isNotEmpty(argument.get("value"))) {
|
||||
params.add(argument.get("name") + "=" + URLEncoder.encode(argument.get("value")));
|
||||
}
|
||||
}
|
||||
if(CollectionUtils.isNotEmpty(params)){
|
||||
if (CollectionUtils.isNotEmpty(params)) {
|
||||
apiDefinition.setUrl(apiDefinition.getUrl() + "?" + StringUtils.join(params, "&"));
|
||||
}
|
||||
response = HttpClientUtil.get(apiDefinition.getUrl().trim(), httpClientConfig);
|
||||
@ -167,7 +168,7 @@ public class ApiProvider extends Provider {
|
||||
if (StringUtils.equalsAny(type, "Form_Data", "WWW_FORM")) {
|
||||
if (apiDefinitionRequest.getBody().get("kvs") != null) {
|
||||
Map<String, String> body = new HashMap<>();
|
||||
JSONObject bodyObj = JSONObject.parseObject(apiDefinitionRequest.getBody().toString());
|
||||
JSONObject bodyObj = JSONObject.parseObject(apiDefinitionRequest.getBody().toString(), Feature.IgnoreNotMatch);
|
||||
JSONArray kvsArr = bodyObj.getJSONArray("kvs");
|
||||
for (int i = 0; i < kvsArr.size(); i++) {
|
||||
JSONObject kv = kvsArr.getJSONObject(i);
|
||||
@ -267,9 +268,12 @@ public class ApiProvider extends Provider {
|
||||
handleStr(apiDefinition, o.toString(), fields, rootPath);
|
||||
}
|
||||
} else {
|
||||
JSONObject jsonObject = JSONObject.parseObject(jsonStr);
|
||||
JSONObject jsonObject = JSONObject.parseObject(jsonStr, Feature.IgnoreNotMatch);
|
||||
for (String s : jsonObject.keySet()) {
|
||||
String value = jsonObject.getString(s);
|
||||
if (StringUtils.isNotEmpty(value) && value.startsWith("{")) {
|
||||
value = JSONObject.toJSONString(jsonObject.getJSONObject(s), SerializerFeature.WriteMapNullValue);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(value) && value.startsWith("[")) {
|
||||
JSONObject o = new JSONObject();
|
||||
try {
|
||||
@ -283,7 +287,7 @@ public class ApiProvider extends Provider {
|
||||
|
||||
} catch (Exception e) {
|
||||
JSONArray array = new JSONArray();
|
||||
array.add(StringUtils.isNotEmpty(jsonObject.getString(s)) ? jsonObject.getString(s) : "");
|
||||
array.add(StringUtils.isNotEmpty(value) ? value : "");
|
||||
o.put("value", array);
|
||||
}
|
||||
o.put("jsonPath", rootPath + "." + String.format(path, s));
|
||||
@ -293,9 +297,9 @@ public class ApiProvider extends Provider {
|
||||
}
|
||||
} else if (StringUtils.isNotEmpty(value) && value.startsWith("{")) {
|
||||
try {
|
||||
JSONObject.parseObject(jsonStr);
|
||||
JSONObject.parseObject(value, Feature.IgnoreNotMatch);
|
||||
List<JSONObject> children = new ArrayList<>();
|
||||
handleStr(apiDefinition, jsonObject.getString(s), children, rootPath + "." + String.format(path, s));
|
||||
handleStr(apiDefinition, value, children, rootPath + "." + String.format(path, s));
|
||||
JSONObject o = new JSONObject();
|
||||
o.put("children", children);
|
||||
o.put("childrenDataType", "OBJECT");
|
||||
@ -304,12 +308,13 @@ public class ApiProvider extends Provider {
|
||||
if (!hasItem(apiDefinition, fields, o)) {
|
||||
fields.add(o);
|
||||
}
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JSONObject o = new JSONObject();
|
||||
o.put("jsonPath", rootPath + "." + String.format(path, s));
|
||||
setProperty(apiDefinition, o, s);
|
||||
JSONArray array = new JSONArray();
|
||||
array.add(StringUtils.isNotEmpty(jsonObject.getString(s)) ? jsonObject.getString(s) : "");
|
||||
array.add(StringUtils.isNotEmpty(value) ? value : "");
|
||||
o.put("value", array);
|
||||
if (!hasItem(apiDefinition, fields, o)) {
|
||||
fields.add(o);
|
||||
@ -320,7 +325,7 @@ public class ApiProvider extends Provider {
|
||||
o.put("jsonPath", rootPath + "." + String.format(path, s));
|
||||
setProperty(apiDefinition, o, s);
|
||||
JSONArray array = new JSONArray();
|
||||
array.add(StringUtils.isNotEmpty(jsonObject.getString(s)) ? jsonObject.getString(s) : "");
|
||||
array.add(StringUtils.isNotEmpty(value) ? value : "");
|
||||
o.put("value", array);
|
||||
if (!hasItem(apiDefinition, fields, o)) {
|
||||
fields.add(o);
|
||||
@ -376,9 +381,9 @@ public class ApiProvider extends Provider {
|
||||
}
|
||||
for (Object itemChild : itemChildren) {
|
||||
boolean hasKey = false;
|
||||
JSONObject itemChildObject = JSONObject.parseObject(itemChild.toString());
|
||||
JSONObject itemChildObject = JSONObject.parseObject(itemChild.toString(), Feature.IgnoreNotMatch);
|
||||
for (Object fieldChild : fieldChildren) {
|
||||
JSONObject fieldChildObject = JSONObject.parseObject(fieldChild.toString());
|
||||
JSONObject fieldChildObject = JSONObject.parseObject(fieldChild.toString(), Feature.IgnoreNotMatch);
|
||||
if (itemChildObject.getString("jsonPath").equals(fieldChildObject.getString("jsonPath"))) {
|
||||
mergeField(fieldChildObject, itemChildObject);
|
||||
hasKey = true;
|
||||
@ -403,10 +408,10 @@ public class ApiProvider extends Provider {
|
||||
|
||||
JSONArray fieldArrayChildren = new JSONArray();
|
||||
for (Object fieldChild : fieldChildren) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(fieldChild.toString());
|
||||
JSONObject jsonObject = JSONObject.parseObject(fieldChild.toString(), Feature.IgnoreNotMatch);
|
||||
JSONObject find = null;
|
||||
for (Object itemChild : itemChildren) {
|
||||
JSONObject itemObject = JSONObject.parseObject(itemChild.toString());
|
||||
JSONObject itemObject = JSONObject.parseObject(itemChild.toString(), Feature.IgnoreNotMatch);
|
||||
if (jsonObject.getString("jsonPath").equals(itemObject.getString("jsonPath"))) {
|
||||
find = itemObject;
|
||||
}
|
||||
@ -422,7 +427,7 @@ public class ApiProvider extends Provider {
|
||||
|
||||
private List<String[]> fetchResult(String result, ApiDefinition apiDefinition) {
|
||||
List<String[]> dataList = new LinkedList<>();
|
||||
if(apiDefinition.isUseJsonPath()){
|
||||
if (apiDefinition.isUseJsonPath()) {
|
||||
List<LinkedHashMap> currentData = new ArrayList<>();
|
||||
Object object = JsonPath.read(result, apiDefinition.getJsonPath());
|
||||
if (object instanceof List) {
|
||||
@ -439,7 +444,7 @@ public class ApiProvider extends Provider {
|
||||
}
|
||||
dataList.add(row);
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
if (StringUtils.isNotEmpty(apiDefinition.getDataPath()) && CollectionUtils.isEmpty(apiDefinition.getJsonFields())) {
|
||||
List<LinkedHashMap> currentData = new ArrayList<>();
|
||||
Object object = JsonPath.read(result, apiDefinition.getDataPath());
|
||||
|
@ -1116,6 +1116,19 @@ public class DataSetTableService {
|
||||
}
|
||||
|
||||
private String handlePlainSelect(PlainSelect plainSelect, Select statementSelect, String dsType) throws Exception {
|
||||
|
||||
List<SelectItem> selectItems = new ArrayList<>();
|
||||
plainSelect.getSelectItems().forEach(selectItem -> {
|
||||
System.out.println(selectItem);
|
||||
System.out.println(selectItem instanceof PlainSelect);
|
||||
System.out.println(selectItem instanceof SubSelect);
|
||||
|
||||
selectItems.add(selectItem);
|
||||
});
|
||||
|
||||
plainSelect.addSelectItems(selectItems);
|
||||
|
||||
|
||||
FromItem fromItem = plainSelect.getFromItem();
|
||||
if (fromItem instanceof SubSelect) {
|
||||
SelectBody selectBody = ((SubSelect) fromItem).getSelectBody();
|
||||
|
@ -277,3 +277,4 @@ I18N_PANEL_PDF_TEMPLATE_ONLY_PIC=Default template only screenshot
|
||||
\u8FB9\u684610=Border 10
|
||||
I18n_name_cant_empty=Name can not be empty!
|
||||
I18n_del_admin_tips=Forbidden to delete the admin account
|
||||
I18N_NO_DRIVER_PERMISSION=Do not have permissions!
|
@ -267,4 +267,5 @@ I18N_PANEL_PDF_TEMPLATE_WITH_PARAMS=\u9ED8\u8BA4\u6A21\u677F(\u52A0\u4EEA\u8868\
|
||||
I18N_PANEL_PDF_TEMPLATE_ONLY_PIC=\u9ED8\u8BA4\u6A21\u677F(\u53EA\u622A\u56FE)
|
||||
I18n_name_cant_empty=\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A\uFF01
|
||||
I18n_del_admin_tips=\u7981\u6B62\u5220\u9664admin\u8D26\u53F7
|
||||
I18N_NO_DRIVER_PERMISSION=\u6ca1\u6709\u6743\u9650\uff01
|
||||
|
||||
|
@ -273,3 +273,4 @@ I18N_PANEL_PDF_TEMPLATE_ONLY_PIC=\u9ED8\u8A8D\u6A21\u677F(\u53EA\u622A\u5716)
|
||||
\u8FB9\u684610=\u908A\u6846 10
|
||||
I18n_name_cant_empty=\u540D\u7A31\u4E0D\u80FD\u70BA\u7A7A\uFF01
|
||||
I18n_del_admin_tips=\u7981\u6B62\u522A\u9664admin\u8CEC\u865F
|
||||
I18N_NO_DRIVER_PERMISSION=\u6c92\u6709\u8a31\u53ef\u6b0a\uff01
|
@ -13,9 +13,8 @@ public class DmConfig extends JdbcConfiguration {
|
||||
|
||||
|
||||
public String getJdbc() {
|
||||
return "jdbc:dm://HOST:PORT/DATABASE"
|
||||
return "jdbc:dm://HOST:PORT"
|
||||
.replace("HOST", getHost().trim())
|
||||
.replace("PORT", getPort().toString())
|
||||
.replace("DATABASE", getDataBase().trim());
|
||||
.replace("PORT", getPort().toString());
|
||||
}
|
||||
}
|
||||
|
@ -20,10 +20,6 @@
|
||||
<el-input :placeholder="$t('enter_the_port')" v-model="form.configuration.port" autocomplete="off"/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item :label="$t('dataBase')" prop="configuration.dataBase">
|
||||
<el-input v-model="form.configuration.dataBase" autocomplete="off"/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item :label="$t('username')" prop="configuration.username">
|
||||
<el-input :placeholder="$t('one_user_name')" v-model="form.configuration.username" autocomplete="off"/>
|
||||
</el-form-item>
|
||||
|
Loading…
Reference in New Issue
Block a user