forked from github/dataease
fix(数据源): 校验状态没有记录改变
This commit is contained in:
parent
3401731a91
commit
3fca6dce19
@ -144,7 +144,7 @@ public class CalciteProvider {
|
|||||||
String querySql = getTablesSql(datasourceRequest).get(0);
|
String querySql = getTablesSql(datasourceRequest).get(0);
|
||||||
try (Connection con = getConnection(datasourceRequest.getDatasource()); Statement statement = getStatement(con, 30); ResultSet resultSet = statement.executeQuery(querySql)) {
|
try (Connection con = getConnection(datasourceRequest.getDatasource()); Statement statement = getStatement(con, 30); ResultSet resultSet = statement.executeQuery(querySql)) {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
DEException.throwException(e.getMessage());
|
throw e;
|
||||||
}
|
}
|
||||||
return "Success";
|
return "Success";
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,6 @@ import static io.dataease.datasource.server.DatasourceTaskServer.ScheduleType.RI
|
|||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/datasource")
|
@RequestMapping("/datasource")
|
||||||
@Transactional
|
|
||||||
public class DatasourceServer implements DatasourceApi {
|
public class DatasourceServer implements DatasourceApi {
|
||||||
@Resource
|
@Resource
|
||||||
private CoreDatasourceMapper datasourceMapper;
|
private CoreDatasourceMapper datasourceMapper;
|
||||||
@ -120,48 +119,6 @@ public class DatasourceServer implements DatasourceApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void move(DatasourceDTO dataSourceDTO) throws DEException {
|
|
||||||
switch (dataSourceDTO.getAction()) {
|
|
||||||
case "move" -> {
|
|
||||||
if (dataSourceDTO.getPid() == null) {
|
|
||||||
DEException.throwException("目录必选!");
|
|
||||||
}
|
|
||||||
if (Objects.equals(dataSourceDTO.getId(), dataSourceDTO.getPid())) {
|
|
||||||
DEException.throwException(Translator.get("i18n_pid_not_eq_id"));
|
|
||||||
}
|
|
||||||
if (dataSourceDTO.getPid() != 0) {
|
|
||||||
List<Long> ids = new ArrayList<>();
|
|
||||||
getParents(dataSourceDTO.getPid(), ids);
|
|
||||||
if (ids.contains(dataSourceDTO.getId())) {
|
|
||||||
DEException.throwException(Translator.get("i18n_pid_not_eq_id"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dataSourceManage.move(dataSourceDTO);
|
|
||||||
}
|
|
||||||
case "rename" -> {
|
|
||||||
if (StringUtils.isEmpty(dataSourceDTO.getName())) {
|
|
||||||
DEException.throwException("名称不能为空!");
|
|
||||||
}
|
|
||||||
CoreDatasource datasource = datasourceMapper.selectById(dataSourceDTO.getId());
|
|
||||||
datasource.setName(dataSourceDTO.getName());
|
|
||||||
dataSourceManage.innerEdit(datasource);
|
|
||||||
}
|
|
||||||
case "create" -> {
|
|
||||||
CoreDatasource coreDatasource = new CoreDatasource();
|
|
||||||
BeanUtils.copyBean(coreDatasource, dataSourceDTO);
|
|
||||||
coreDatasource.setCreateTime(System.currentTimeMillis());
|
|
||||||
coreDatasource.setUpdateTime(System.currentTimeMillis());
|
|
||||||
coreDatasource.setTaskStatus(TaskStatus.WaitingForExecution.name());
|
|
||||||
coreDatasource.setType(dataSourceDTO.getNodeType());
|
|
||||||
coreDatasource.setId(IDUtils.snowID());
|
|
||||||
coreDatasource.setConfiguration("");
|
|
||||||
dataSourceManage.innerSave(coreDatasource);
|
|
||||||
}
|
|
||||||
default -> {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void filterDs(List<BusiNodeVO> busiNodeVOS, List<Long> ids, String type, Long id) {
|
private void filterDs(List<BusiNodeVO> busiNodeVOS, List<Long> ids, String type, Long id) {
|
||||||
for (BusiNodeVO busiNodeVO : busiNodeVOS) {
|
for (BusiNodeVO busiNodeVO : busiNodeVOS) {
|
||||||
if (busiNodeVO.getType() != null && busiNodeVO.getType().equalsIgnoreCase(type)) {
|
if (busiNodeVO.getType() != null && busiNodeVO.getType().equalsIgnoreCase(type)) {
|
||||||
@ -231,16 +188,53 @@ public class DatasourceServer implements DatasourceApi {
|
|||||||
return hasRepeat;
|
return hasRepeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public DatasourceDTO move(DatasourceDTO dataSourceDTO) {
|
||||||
|
if (dataSourceDTO.getPid() == null) {
|
||||||
|
DEException.throwException("目录必选!");
|
||||||
|
}
|
||||||
|
if (Objects.equals(dataSourceDTO.getId(), dataSourceDTO.getPid())) {
|
||||||
|
DEException.throwException(Translator.get("i18n_pid_not_eq_id"));
|
||||||
|
}
|
||||||
|
if (dataSourceDTO.getPid() != 0) {
|
||||||
|
List<Long> ids = new ArrayList<>();
|
||||||
|
getParents(dataSourceDTO.getPid(), ids);
|
||||||
|
if (ids.contains(dataSourceDTO.getId())) {
|
||||||
|
DEException.throwException(Translator.get("i18n_pid_not_eq_id"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dataSourceManage.move(dataSourceDTO);
|
||||||
|
return dataSourceDTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public DatasourceDTO reName(DatasourceDTO dataSourceDTO) {
|
||||||
|
if (StringUtils.isEmpty(dataSourceDTO.getName())) {
|
||||||
|
DEException.throwException("名称不能为空!");
|
||||||
|
}
|
||||||
|
CoreDatasource datasource = datasourceMapper.selectById(dataSourceDTO.getId());
|
||||||
|
datasource.setName(dataSourceDTO.getName());
|
||||||
|
dataSourceManage.innerEdit(datasource);
|
||||||
|
return dataSourceDTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public DatasourceDTO createFolder(DatasourceDTO dataSourceDTO) {
|
||||||
|
dataSourceDTO.setCreateTime(System.currentTimeMillis());
|
||||||
|
dataSourceDTO.setUpdateTime(System.currentTimeMillis());
|
||||||
|
dataSourceDTO.setType(dataSourceDTO.getNodeType());
|
||||||
|
dataSourceDTO.setId(IDUtils.snowID());
|
||||||
|
dataSourceDTO.setConfiguration("");
|
||||||
|
CoreDatasource coreDatasource = new CoreDatasource();
|
||||||
|
coreDatasource.setTaskStatus(TaskStatus.WaitingForExecution.name());
|
||||||
|
BeanUtils.copyBean(coreDatasource, dataSourceDTO);
|
||||||
|
dataSourceManage.innerSave(coreDatasource);
|
||||||
|
return dataSourceDTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public DatasourceDTO save(DatasourceDTO dataSourceDTO) throws DEException {
|
public DatasourceDTO save(DatasourceDTO dataSourceDTO) throws DEException {
|
||||||
if (StringUtils.isNotEmpty(dataSourceDTO.getAction())) {
|
|
||||||
move(dataSourceDTO);
|
|
||||||
return dataSourceDTO;
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotEmpty(dataSourceDTO.getNodeType()) && dataSourceDTO.getNodeType().equalsIgnoreCase("folder")) {
|
|
||||||
dataSourceDTO.setType("folder");
|
|
||||||
dataSourceDTO.setConfiguration("");
|
|
||||||
}
|
|
||||||
if (dataSourceDTO.getId() != null && dataSourceDTO.getId() > 0) {
|
if (dataSourceDTO.getId() != null && dataSourceDTO.getId() > 0) {
|
||||||
return update(dataSourceDTO);
|
return update(dataSourceDTO);
|
||||||
}
|
}
|
||||||
@ -256,6 +250,7 @@ public class DatasourceServer implements DatasourceApi {
|
|||||||
try {
|
try {
|
||||||
checkDatasourceStatus(coreDatasource);
|
checkDatasourceStatus(coreDatasource);
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
|
coreDatasource.setStatus("Error");
|
||||||
}
|
}
|
||||||
coreDatasource.setTaskStatus(TaskStatus.WaitingForExecution.name());
|
coreDatasource.setTaskStatus(TaskStatus.WaitingForExecution.name());
|
||||||
coreDatasource.setCreateBy(AuthUtils.getUser().getUserId().toString());
|
coreDatasource.setCreateBy(AuthUtils.getUser().getUserId().toString());
|
||||||
@ -316,32 +311,6 @@ public class DatasourceServer implements DatasourceApi {
|
|||||||
return dataSourceDTO;
|
return dataSourceDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkParams(String configurationStr) {
|
|
||||||
DatasourceConfiguration configuration = JsonUtil.parseObject(configurationStr, DatasourceConfiguration.class);
|
|
||||||
if (configuration.getInitialPoolSize() < configuration.getMinPoolSize()) {
|
|
||||||
DEException.throwException("初始连接数不能小于最小连接数!");
|
|
||||||
}
|
|
||||||
if (configuration.getInitialPoolSize() > configuration.getMaxPoolSize()) {
|
|
||||||
DEException.throwException("初始连接数不能大于最大连接数!");
|
|
||||||
}
|
|
||||||
if (configuration.getMaxPoolSize() < configuration.getMinPoolSize()) {
|
|
||||||
DEException.throwException("最大连接数不能小于最小连接数!");
|
|
||||||
}
|
|
||||||
if (configuration.getQueryTimeout() < 0) {
|
|
||||||
DEException.throwException("查询超时不能小于0!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void checkName(List<String> tables) {
|
|
||||||
for (int i = 0; i < tables.size() - 1; i++) {
|
|
||||||
for (int j = i + 1; j < tables.size(); j++) {
|
|
||||||
if (tables.get(i).equalsIgnoreCase(tables.get(j))) {
|
|
||||||
DEException.throwException(Translator.get("i18n_table_name_repeat") + tables.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DatasourceDTO update(DatasourceDTO dataSourceDTO) throws DEException {
|
public DatasourceDTO update(DatasourceDTO dataSourceDTO) throws DEException {
|
||||||
Long pk = null;
|
Long pk = null;
|
||||||
if (ObjectUtils.isEmpty(pk = dataSourceDTO.getId())) {
|
if (ObjectUtils.isEmpty(pk = dataSourceDTO.getId())) {
|
||||||
@ -358,7 +327,8 @@ public class DatasourceServer implements DatasourceApi {
|
|||||||
requestDatasource.setUpdateBy(AuthUtils.getUser().getUserId());
|
requestDatasource.setUpdateBy(AuthUtils.getUser().getUserId());
|
||||||
try {
|
try {
|
||||||
checkDatasourceStatus(requestDatasource);
|
checkDatasourceStatus(requestDatasource);
|
||||||
} catch (Exception ignore) {
|
} catch (Exception e) {
|
||||||
|
requestDatasource.setStatus("Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
DatasourceRequest sourceTableRequest = new DatasourceRequest();
|
DatasourceRequest sourceTableRequest = new DatasourceRequest();
|
||||||
@ -455,6 +425,32 @@ public class DatasourceServer implements DatasourceApi {
|
|||||||
return dataSourceDTO;
|
return dataSourceDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void checkParams(String configurationStr) {
|
||||||
|
DatasourceConfiguration configuration = JsonUtil.parseObject(configurationStr, DatasourceConfiguration.class);
|
||||||
|
if (configuration.getInitialPoolSize() < configuration.getMinPoolSize()) {
|
||||||
|
DEException.throwException("初始连接数不能小于最小连接数!");
|
||||||
|
}
|
||||||
|
if (configuration.getInitialPoolSize() > configuration.getMaxPoolSize()) {
|
||||||
|
DEException.throwException("初始连接数不能大于最大连接数!");
|
||||||
|
}
|
||||||
|
if (configuration.getMaxPoolSize() < configuration.getMinPoolSize()) {
|
||||||
|
DEException.throwException("最大连接数不能小于最小连接数!");
|
||||||
|
}
|
||||||
|
if (configuration.getQueryTimeout() < 0) {
|
||||||
|
DEException.throwException("查询超时不能小于0!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void checkName(List<String> tables) {
|
||||||
|
for (int i = 0; i < tables.size() - 1; i++) {
|
||||||
|
for (int j = i + 1; j < tables.size(); j++) {
|
||||||
|
if (tables.get(i).equalsIgnoreCase(tables.get(j))) {
|
||||||
|
DEException.throwException(Translator.get("i18n_table_name_repeat") + tables.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String excelDataTableName(String name) {
|
private String excelDataTableName(String name) {
|
||||||
return StringUtils.substring(name, 6, name.length() - 11);
|
return StringUtils.substring(name, 6, name.length() - 11);
|
||||||
}
|
}
|
||||||
@ -553,6 +549,7 @@ public class DatasourceServer implements DatasourceApi {
|
|||||||
return datasourceDTO;
|
return datasourceDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
@DeLog(id = "#p0", ot = LogOT.DELETE, st = LogST.DATASOURCE)
|
@DeLog(id = "#p0", ot = LogOT.DELETE, st = LogST.DATASOURCE)
|
||||||
@Override
|
@Override
|
||||||
@XpackInteract(value = "datasourceResourceTree", before = false)
|
@XpackInteract(value = "datasourceResourceTree", before = false)
|
||||||
@ -615,7 +612,8 @@ public class DatasourceServer implements DatasourceApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatasourceDTO validate(Long datasourceId) throws DEException {
|
public DatasourceDTO validate(Long datasourceId) throws DEException {
|
||||||
CoreDatasource coreDatasource = datasourceMapper.selectById(datasourceId);
|
CoreDatasource coreDatasource = new CoreDatasource();
|
||||||
|
BeanUtils.copyBean(coreDatasource, datasourceMapper.selectById(datasourceId));
|
||||||
return validate(coreDatasource);
|
return validate(coreDatasource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -645,19 +643,24 @@ public class DatasourceServer implements DatasourceApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private DatasourceDTO validate(CoreDatasource coreDatasource) {
|
private DatasourceDTO validate(CoreDatasource coreDatasource) {
|
||||||
checkDatasourceStatus(coreDatasource);
|
|
||||||
DatasourceDTO datasourceDTO = new DatasourceDTO();
|
DatasourceDTO datasourceDTO = new DatasourceDTO();
|
||||||
BeanUtils.copyBean(datasourceDTO, coreDatasource);
|
BeanUtils.copyBean(datasourceDTO, coreDatasource);
|
||||||
CoreDatasource record = new CoreDatasource();
|
try {
|
||||||
record.setStatus(coreDatasource.getStatus());
|
checkDatasourceStatus(coreDatasource);
|
||||||
QueryWrapper<CoreDatasource> wrapper = new QueryWrapper<>();
|
} catch (Exception e) {
|
||||||
wrapper.eq("id", coreDatasource.getId());
|
coreDatasource.setStatus("Error");
|
||||||
CoreDatasource originData = datasourceMapper.selectById(coreDatasource.getId());
|
DEException.throwException(e.getMessage());
|
||||||
String originStatus = originData.getStatus();
|
} finally {
|
||||||
if (StringUtils.equals(coreDatasource.getStatus(), originStatus)) {
|
datasourceDTO.setStatus(coreDatasource.getStatus());
|
||||||
return datasourceDTO;
|
QueryWrapper<CoreDatasource> wrapper = new QueryWrapper<>();
|
||||||
|
wrapper.eq("id", coreDatasource.getId());
|
||||||
|
CoreDatasource originData = datasourceMapper.selectById(coreDatasource.getId());
|
||||||
|
String originStatus = originData.getStatus();
|
||||||
|
if (!StringUtils.equals(coreDatasource.getStatus(), originStatus)) {
|
||||||
|
dataSourceManage.innerEditStatus(coreDatasource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dataSourceManage.innerEditStatus(coreDatasource);
|
datasourceDTO.setConfiguration("");
|
||||||
return datasourceDTO;
|
return datasourceDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -838,7 +841,7 @@ public class DatasourceServer implements DatasourceApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkDatasourceStatus(CoreDatasource coreDatasource) throws DEException {
|
public void checkDatasourceStatus(CoreDatasource coreDatasource) {
|
||||||
if (coreDatasource.getType().equals(DatasourceConfiguration.DatasourceType.Excel.name()) || coreDatasource.getType().equals(DatasourceConfiguration.DatasourceType.folder.name())) {
|
if (coreDatasource.getType().equals(DatasourceConfiguration.DatasourceType.Excel.name()) || coreDatasource.getType().equals(DatasourceConfiguration.DatasourceType.folder.name())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -853,8 +856,7 @@ public class DatasourceServer implements DatasourceApi {
|
|||||||
}
|
}
|
||||||
coreDatasource.setStatus(status);
|
coreDatasource.setStatus(status);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
coreDatasource.setStatus("Error");
|
DEException.throwException(e.getMessage());
|
||||||
DEException.throwException("校验失败: " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user