fix: 数据源校验

This commit is contained in:
taojinlong 2021-08-24 15:03:17 +08:00
parent 461f5135de
commit e83510f4b7
4 changed files with 22 additions and 11 deletions

View File

@ -38,8 +38,8 @@ public class DatasourceController {
@ApiOperation("验证数据源")
@PostMapping("/validate")
public void validate(@RequestBody Datasource datasource) throws Exception {
datasourceService.validate(datasource);
public ResultHolder validate(@RequestBody Datasource datasource) throws Exception {
return datasourceService.validate(datasource);
}
@ApiOperation("验证数据源")

View File

@ -120,11 +120,17 @@ public class DatasourceService {
checkAndUpdateDatasourceStatus(datasource);
}
public void validate(Datasource datasource) throws Exception {
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(datasource.getType());
DatasourceRequest datasourceRequest = new DatasourceRequest();
datasourceRequest.setDatasource(datasource);
datasourceProvider.checkStatus(datasourceRequest);
public ResultHolder validate(Datasource datasource) throws Exception {
try {
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(datasource.getType());
DatasourceRequest datasourceRequest = new DatasourceRequest();
datasourceRequest.setDatasource(datasource);
datasourceProvider.checkStatus(datasourceRequest);
return ResultHolder.success("Success");
}catch (Exception e){
return ResultHolder.error("Datasource is invalid: " + e.getMessage());
}
}
public ResultHolder validate(String datasourceId) {
@ -133,7 +139,10 @@ public class DatasourceService {
return ResultHolder.error("Can not find datasource: "+ datasourceId);
}
try {
validate(datasource);
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(datasource.getType());
DatasourceRequest datasourceRequest = new DatasourceRequest();
datasourceRequest.setDatasource(datasource);
datasourceProvider.checkStatus(datasourceRequest);
datasource.setStatus("Success");
return ResultHolder.success("Success");
}catch (Exception e){

View File

@ -572,7 +572,9 @@ public class ExtractDataService {
}
private void extractData(DatasetTable datasetTable, String extractType) throws Exception {
datasourceService.validate(datasetTable.getDataSourceId());
if(StringUtils.isNotEmpty(datasetTable.getDataSourceId())){
datasourceService.validate(datasetTable.getDataSourceId());
}
KettleFileRepository repository = CommonBeanFactory.getBean(KettleFileRepository.class);
RepositoryDirectoryInterface repositoryDirectoryInterface = repository.loadRepositoryDirectoryTree();
TransMeta transMeta = null;

View File

@ -278,7 +278,7 @@ export default {
data.configuration = JSON.stringify(data.configuration)
if(data.showModel === 'show' && !this.canEdit){
validateDsById(data.id).then(res => {
if(res.success === 'true'){
if(res.success){
this.$success(this.$t('datasource.validate_success'))
}else {
this.$error(this.$t(res.message))
@ -290,7 +290,7 @@ export default {
}else {
validateDs(data).then(res => {
if(res.success === 'true'){
if(res.success){
this.$success(this.$t('datasource.validate_success'))
}else {
this.$error(this.$t(res.message))