diff --git a/core/backend/src/main/java/io/dataease/controller/datasource/DriverMgmController.java b/core/backend/src/main/java/io/dataease/controller/datasource/DriverMgmController.java index 784091daf9..32edc4ae23 100644 --- a/core/backend/src/main/java/io/dataease/controller/datasource/DriverMgmController.java +++ b/core/backend/src/main/java/io/dataease/controller/datasource/DriverMgmController.java @@ -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 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 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 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")); + } + } } diff --git a/core/backend/src/main/java/io/dataease/provider/datasource/ApiProvider.java b/core/backend/src/main/java/io/dataease/provider/datasource/ApiProvider.java index b6695e6e4b..0b4adc7626 100644 --- a/core/backend/src/main/java/io/dataease/provider/datasource/ApiProvider.java +++ b/core/backend/src/main/java/io/dataease/provider/datasource/ApiProvider.java @@ -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 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 dataList = new ArrayList<>(); List 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); @@ -141,13 +142,13 @@ public class ApiProvider extends Provider { switch (apiDefinition.getMethod()) { case "GET": - List params = new ArrayList<>(); + List params = new ArrayList<>(); for (Map 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 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 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 fetchResult(String result, ApiDefinition apiDefinition) { List dataList = new LinkedList<>(); - if(apiDefinition.isUseJsonPath()){ + if (apiDefinition.isUseJsonPath()) { List 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 currentData = new ArrayList<>(); Object object = JsonPath.read(result, apiDefinition.getDataPath()); diff --git a/core/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/core/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index d5561c0148..3b6b890970 100644 --- a/core/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/core/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -1116,6 +1116,19 @@ public class DataSetTableService { } private String handlePlainSelect(PlainSelect plainSelect, Select statementSelect, String dsType) throws Exception { + + List 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(); diff --git a/core/backend/src/main/resources/i18n/messages_en_US.properties b/core/backend/src/main/resources/i18n/messages_en_US.properties index 8535f00ccf..48c85b8c64 100644 --- a/core/backend/src/main/resources/i18n/messages_en_US.properties +++ b/core/backend/src/main/resources/i18n/messages_en_US.properties @@ -276,4 +276,5 @@ I18N_PANEL_PDF_TEMPLATE_ONLY_PIC=Default template only screenshot \u8FB9\u68469=Border 9 \u8FB9\u684610=Border 10 I18n_name_cant_empty=Name can not be empty! -I18n_del_admin_tips=Forbidden to delete the admin account \ No newline at end of file +I18n_del_admin_tips=Forbidden to delete the admin account +I18N_NO_DRIVER_PERMISSION=Do not have permissions! \ No newline at end of file diff --git a/core/backend/src/main/resources/i18n/messages_zh_CN.properties b/core/backend/src/main/resources/i18n/messages_zh_CN.properties index 2ee6665983..ff5de5ab72 100644 --- a/core/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/core/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -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 diff --git a/core/backend/src/main/resources/i18n/messages_zh_TW.properties b/core/backend/src/main/resources/i18n/messages_zh_TW.properties index 3b56bd3ecc..9898eb0b13 100644 --- a/core/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/core/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -272,4 +272,5 @@ I18N_PANEL_PDF_TEMPLATE_ONLY_PIC=\u9ED8\u8A8D\u6A21\u677F(\u53EA\u622A\u5716) \u8FB9\u68469=\u908A\u6846 9 \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 \ No newline at end of file +I18n_del_admin_tips=\u7981\u6B62\u522A\u9664admin\u8CEC\u865F +I18N_NO_DRIVER_PERMISSION=\u6c92\u6709\u8a31\u53ef\u6b0a\uff01 \ No newline at end of file diff --git a/extensions/dataease-extensions-datasource/dm/dm-backend/src/main/java/io/dataease/plugins/datasource/dm/provider/DmConfig.java b/extensions/dataease-extensions-datasource/dm/dm-backend/src/main/java/io/dataease/plugins/datasource/dm/provider/DmConfig.java index e1d07a3167..16f7eb1200 100644 --- a/extensions/dataease-extensions-datasource/dm/dm-backend/src/main/java/io/dataease/plugins/datasource/dm/provider/DmConfig.java +++ b/extensions/dataease-extensions-datasource/dm/dm-backend/src/main/java/io/dataease/plugins/datasource/dm/provider/DmConfig.java @@ -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()); } } diff --git a/extensions/dataease-extensions-datasource/dm/dm-frontend/src/views/dm.vue b/extensions/dataease-extensions-datasource/dm/dm-frontend/src/views/dm.vue index 35dc3badef..d8ef255152 100644 --- a/extensions/dataease-extensions-datasource/dm/dm-frontend/src/views/dm.vue +++ b/extensions/dataease-extensions-datasource/dm/dm-frontend/src/views/dm.vue @@ -20,10 +20,6 @@ - - - -