提交 4a5935ca authored 作者: wangjiahao's avatar wangjiahao

feat: 优化代码格式 异常抛出优化

上级 3f94b2f7
......@@ -7,6 +7,7 @@ import io.dataease.auth.service.AuthUserService;
import io.dataease.auth.util.JWTUtils;
import io.dataease.commons.utils.CommonBeanFactory;
import io.dataease.commons.utils.LogUtil;
import io.dataease.exception.DataEaseException;
import io.dataease.i18n.Translator;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authc.AuthenticationException;
......@@ -95,7 +96,7 @@ public class JWTFilter extends BasicHttpAuthenticationFilter {
AuthUserService authUserService = CommonBeanFactory.getBean(AuthUserService.class);
SysUserEntity user = authUserService.getUserById(tokenInfo.getUserId());
if(user == null){
throw new Exception(Translator.get("i18n_not_find_user"));
DataEaseException.throwException(Translator.get("i18n_not_find_user"));
}
String password = user.getPassword();
......
......@@ -14,6 +14,7 @@ import io.dataease.commons.utils.BeanUtils;
import io.dataease.commons.utils.CodingUtil;
import io.dataease.commons.utils.ServletUtils;
import io.dataease.exception.DataEaseException;
import io.dataease.i18n.Translator;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -40,10 +41,10 @@ public class AuthServer implements AuthApi {
SysUserEntity user = authUserService.getUserByName(username);
if (ObjectUtils.isEmpty(user)) {
throw new RuntimeException(Translator.get("i18n_id_or_pwd_error"));
DataEaseException.throwException(Translator.get("i18n_id_or_pwd_error"));
}
if (user.getEnabled() == 0) {
throw new RuntimeException(Translator.get("i18n_id_or_pwd_error"));
DataEaseException.throwException(Translator.get("i18n_id_or_pwd_error"));
}
String realPwd = user.getPassword();
//私钥解密
......@@ -52,7 +53,7 @@ public class AuthServer implements AuthApi {
pwd = CodingUtil.md5(pwd);
if (!StringUtils.equals(pwd, realPwd)) {
throw new RuntimeException(Translator.get("i18n_id_or_pwd_error"));
DataEaseException.throwException(Translator.get("i18n_id_or_pwd_error"));
}
Map<String, Object> result = new HashMap<>();
TokenInfo tokenInfo = TokenInfo.builder().userId(user.getUserId()).username(username).build();
......
......@@ -7,6 +7,7 @@ import com.auth0.jwt.exceptions.JWTDecodeException;
import com.auth0.jwt.interfaces.DecodedJWT;
import io.dataease.auth.entity.TokenInfo;
import io.dataease.commons.utils.CommonBeanFactory;
import io.dataease.exception.DataEaseException;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.env.Environment;
......@@ -50,7 +51,7 @@ public class JWTUtils {
String username = jwt.getClaim("username").asString();
Long userId = jwt.getClaim("userId").asLong();
if (StringUtils.isEmpty(username) || ObjectUtils.isEmpty(userId) ){
throw new RuntimeException("token格式错误!");
DataEaseException.throwException("token格式错误!");
}
TokenInfo tokenInfo = TokenInfo.builder().username(username).userId(userId).build();
return tokenInfo;
......
......@@ -5,6 +5,7 @@ package io.dataease.controller;
import com.google.gson.Gson;
import io.dataease.commons.license.DefaultLicenseService;
import io.dataease.commons.license.F2CLicenseResponse;
import io.dataease.exception.DataEaseException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -35,11 +36,12 @@ public class LicenseController {
return ResultHolder.success(null);
case expired:
String expired = f2CLicenseResponse.getLicense().getExpired();
throw new Exception("License has expired since " + expired + ", please update license.");
DataEaseException.throwException("License has expired since " + expired + ", please update license.");
case invalid:
throw new Exception(f2CLicenseResponse.getMessage());
DataEaseException.throwException(f2CLicenseResponse.getMessage());
default:
throw new Exception("Invalid License.");
DataEaseException.throwException("Invalid License.");
}
return new ResultHolder();
}
}
......@@ -7,6 +7,7 @@ import io.dataease.datasource.dto.MysqlConfigration;
import io.dataease.datasource.dto.SqlServerConfigration;
import io.dataease.datasource.dto.TableFiled;
import io.dataease.datasource.request.DatasourceRequest;
import io.dataease.exception.DataEaseException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
......@@ -31,9 +32,9 @@ public class JdbcProvider extends DatasourceProvider {
ResultSet rs = stat.executeQuery(datasourceRequest.getQuery());
list = fetchResult(rs);
} catch (SQLException e) {
throw new Exception("ERROR:" + e.getMessage(), e);
DataEaseException.throwException(e);
} catch (Exception e) {
throw new Exception("ERROR:" + e.getMessage(), e);
DataEaseException.throwException(e);
} finally {
if(connection != null){
connection.close();
......@@ -50,9 +51,9 @@ public class JdbcProvider extends DatasourceProvider {
Boolean result = stat.execute(datasourceRequest.getQuery());
stat.close();
} catch (SQLException e) {
throw new Exception("ERROR:" + e.getMessage(), e);
DataEaseException.throwException(e);
} catch (Exception e) {
throw new Exception("ERROR:" + e.getMessage(), e);
DataEaseException.throwException(e);
} finally {
if(connection != null){
connection.close();
......@@ -70,14 +71,15 @@ public class JdbcProvider extends DatasourceProvider {
rs = stat.executeQuery(datasourceRequest.getQuery());
return fetchResult(rs);
} catch (SQLException e) {
throw new Exception("ERROR:" + e.getMessage(), e);
DataEaseException.throwException(e);
} catch (Exception e) {
throw new Exception("ERROR:" + e.getMessage(), e);
DataEaseException.throwException(e);
} finally {
if(connection != null){
connection.close();
}
}
return new ArrayList<>();
}
private List<String[]> fetchResult(ResultSet rs) throws Exception {
......@@ -112,14 +114,15 @@ public class JdbcProvider extends DatasourceProvider {
rs = stat.executeQuery(datasourceRequest.getQuery());
return fetchResultField(rs);
} catch (SQLException e) {
throw new Exception("ERROR:" + e.getMessage(), e);
DataEaseException.throwException(e);
} catch (Exception e) {
throw new Exception("ERROR:" + e.getMessage(), e);
DataEaseException.throwException(e);
} finally {
if(connection != null){
connection.close();
}
}
return new ArrayList<>();
}
@Override
......@@ -139,14 +142,15 @@ public class JdbcProvider extends DatasourceProvider {
result.put("fieldList", fieldList);
return result;
} catch (SQLException e) {
throw new Exception("ERROR:" + e.getMessage(), e);
DataEaseException.throwException(e);
} catch (Exception e) {
throw new Exception("ERROR:" + e.getMessage(), e);
DataEaseException.throwException(e);
} finally {
if(connection != null){
connection.close();
}
}
return new HashMap<>();
}
private List<TableFiled> fetchResultField(ResultSet rs) throws Exception {
......@@ -183,12 +187,13 @@ public class JdbcProvider extends DatasourceProvider {
statement.close();
return tables;
} catch (Exception e) {
throw new Exception("ERROR: " + e.getMessage(), e);
DataEaseException.throwException(e);
} finally {
if(con != null){
con.close();
}
}
return new ArrayList<>();
}
@Override
......@@ -222,9 +227,9 @@ public class JdbcProvider extends DatasourceProvider {
}
resultSet.close();
} catch (SQLException e) {
throw new Exception("ERROR:" + e.getMessage(), e);
DataEaseException.throwException(e);
} catch (Exception e) {
throw new Exception("ERROR:" + e.getMessage(), e);
DataEaseException.throwException(e);
} finally {
if(connection != null){
connection.close();
......@@ -244,7 +249,7 @@ public class JdbcProvider extends DatasourceProvider {
resultSet.close();
ps.close();
} catch (Exception e) {
throw new Exception("ERROR: " + e.getMessage(), e);
DataEaseException.throwException(e);
} finally {
if(con != null){con.close();}
}
......@@ -261,7 +266,7 @@ public class JdbcProvider extends DatasourceProvider {
return resultSet.getLong(1);
}
} catch (Exception e) {
throw new Exception("ERROR: " + e.getMessage(), e);
DataEaseException.throwException( e);
} finally {
con.close();
}
......@@ -423,4 +428,4 @@ public class JdbcProvider extends DatasourceProvider {
return "show tables;";
}
}
}
\ No newline at end of file
}
......@@ -18,6 +18,7 @@ import io.dataease.datasource.provider.ProviderFactory;
import io.dataease.datasource.request.DatasourceRequest;
import io.dataease.dto.DatasourceDTO;
import io.dataease.dto.dataset.DataTableInfoDTO;
import io.dataease.exception.DataEaseException;
import io.dataease.i18n.Translator;
import io.dataease.service.dataset.DataSetGroupService;
import org.apache.commons.collections4.CollectionUtils;
......@@ -97,7 +98,7 @@ public class DatasourceService {
example.createCriteria().andDataSourceIdEqualTo(datasourceId);
List<DatasetTable> datasetTables = datasetTableMapper.selectByExample(example);
if(CollectionUtils.isNotEmpty(datasetTables)){
throw new Exception(datasetTables.size() + Translator.get("i18n_datasource_not_allow_delete_msg"));
DataEaseException.throwException(datasetTables.size() + Translator.get("i18n_datasource_not_allow_delete_msg"));
}
datasourceMapper.deleteByPrimaryKey(datasourceId);
}
......
......@@ -4,6 +4,7 @@ import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import io.dataease.commons.utils.LogUtil;
import io.dataease.exception.DataEaseException;
import io.dataease.exception.ExcelException;
import javax.servlet.http.HttpServletResponse;
......@@ -31,10 +32,10 @@ public class EasyExcelExporter {
EasyExcel.write(response.getOutputStream(), this.clazz).registerWriteHandler(horizontalCellStyleStrategy).sheet(sheetName).doWrite(data);
} catch (UnsupportedEncodingException e) {
LogUtil.error(e.getMessage(), e);
throw new ExcelException("Utf-8 encoding is not supported");
DataEaseException.throwException("Utf-8 encoding is not supported");
} catch (IOException e) {
LogUtil.error(e.getMessage(), e);
throw new ExcelException("IO exception");
DataEaseException.throwException("IO exception");
}
}
......
package io.dataease.job.sechedule;
import io.dataease.commons.utils.LogUtil;
import io.dataease.exception.DataEaseException;
import org.quartz.*;
import org.springframework.stereotype.Component;
......@@ -96,7 +97,7 @@ public class ScheduleManager {
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
throw new RuntimeException(e);
DataEaseException.throwException(e);
}
}
......@@ -126,7 +127,7 @@ public class ScheduleManager {
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
throw new RuntimeException(e);
DataEaseException.throwException(e);
}
}
......@@ -187,7 +188,7 @@ public class ScheduleManager {
// addJob(jobName, jobGroupName, triggerName, triggerGroupName, jobClass, cron);
/** 方式二 :先删除,然后在创建一个新的Job */
} catch (Exception e) {
throw new RuntimeException(e);
DataEaseException.throwException(e);
}
}
......@@ -239,7 +240,7 @@ public class ScheduleManager {
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
throw new RuntimeException(e);
DataEaseException.throwException(e);
}
}
......@@ -271,7 +272,7 @@ public class ScheduleManager {
}
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
throw new RuntimeException(e);
DataEaseException.throwException(e);
}
}
......@@ -295,7 +296,7 @@ public class ScheduleManager {
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
throw new RuntimeException(e);
DataEaseException.throwException(e);
}
}
......@@ -305,7 +306,7 @@ public class ScheduleManager {
sched.start();
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
throw new RuntimeException(e);
DataEaseException.throwException(e);
}
}
......@@ -317,7 +318,7 @@ public class ScheduleManager {
}
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
throw new RuntimeException(e);
DataEaseException.throwException(e);
}
}
......@@ -435,7 +436,7 @@ public class ScheduleManager {
public static CronTrigger getCronTrigger(String cron) {
if (!CronExpression.isValidExpression(cron)) {
throw new RuntimeException("cron :" + cron + " error");
DataEaseException.throwException("cron :" + cron + " error");
}
return TriggerBuilder.newTrigger().withIdentity("Calculate Date").withSchedule(CronScheduleBuilder.cronSchedule(cron)).build();
......
......@@ -18,6 +18,7 @@ import io.dataease.datasource.provider.JdbcProvider;
import io.dataease.datasource.provider.ProviderFactory;
import io.dataease.datasource.request.DatasourceRequest;
import io.dataease.dto.dataset.*;
import io.dataease.exception.DataEaseException;
import io.dataease.i18n.Translator;
import io.dataease.provider.DDLProvider;
import io.dataease.provider.QueryProvider;
......@@ -412,7 +413,7 @@ public class DataSetTableService {
String sql = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class).getSql();
if (StringUtils.isEmpty(sql)) {
throw new Exception(Translator.get("i18n_sql_not_empty"));
DataEaseException.throwException(Translator.get("i18n_sql_not_empty"));
}
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
String sqlAsTable = qp.createSQLPreview(sql, null);
......@@ -734,7 +735,7 @@ public class DataSetTableService {
});
sort(sqlFileds);
if (!originNameFileds.equals(sqlFileds)) {
throw new Exception(Translator.get("i18n_sql_add_not_matching") + sqlFileds.toString());
DataEaseException.throwException(Translator.get("i18n_sql_add_not_matching") + sqlFileds.toString());
}
}
if (StringUtils.isNotEmpty(datasetTableIncrementalConfig.getIncrementalDelete()) && StringUtils.isNotEmpty(datasetTableIncrementalConfig.getIncrementalDelete().replace(" ", ""))) {// 增量删除
......@@ -747,7 +748,7 @@ public class DataSetTableService {
});
sort(sqlFileds);
if (!originNameFileds.equals(sqlFileds)) {
throw new Exception(Translator.get("i18n_sql_delete_not_matching") + sqlFileds.toString());
DataEaseException.throwException(Translator.get("i18n_sql_delete_not_matching") + sqlFileds.toString());
}
}
}
......
......@@ -8,6 +8,7 @@ import io.dataease.base.mapper.DatasetTableTaskMapper;
import io.dataease.commons.constants.JobStatus;
import io.dataease.commons.constants.ScheduleType;
import io.dataease.controller.request.dataset.DataSetTaskRequest;
import io.dataease.exception.DataEaseException;
import io.dataease.i18n.Translator;
import io.dataease.service.ScheduleService;
import org.apache.commons.lang3.ObjectUtils;
......@@ -71,11 +72,11 @@ public class DataSetTableTaskService {
if (datasetTableTask.getType().equalsIgnoreCase("add_scope")) {
DatasetTable datasetTable = dataSetTableService.get(datasetTableTask.getTableId());
if (datasetTable.getLastUpdateTime() == 0 || datasetTable.getLastUpdateTime() == null) {
throw new Exception(Translator.get("i18n_not_exec_add_sync"));
DataEaseException.throwException(Translator.get("i18n_not_exec_add_sync"));
}
}
if (extractDataService.updateSyncStatusIsNone(dataSetTableService.get(datasetTableTask.getTableId()))) {
throw new Exception(Translator.get("i18n_sync_job_exists"));
DataEaseException.throwException(Translator.get("i18n_sync_job_exists"));
} else {
//write log
DatasetTableTaskLog datasetTableTaskLog = new DatasetTableTaskLog();
......
......@@ -22,6 +22,7 @@ import io.dataease.datasource.provider.ProviderFactory;
import io.dataease.datasource.request.DatasourceRequest;
import io.dataease.dto.dataset.DataSetTaskLogDTO;
import io.dataease.dto.dataset.DataTableInfoDTO;
import io.dataease.exception.DataEaseException;
import io.dataease.provider.QueryProvider;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FileUtils;
......@@ -461,7 +462,7 @@ public class ExtractDataService {
if (jobStatus.getStatusDescription().equals("Finished")) {
return;
} else {
throw new Exception(jobStatus.getLoggingString());
DataEaseException.throwException((jobStatus.getLoggingString()));
}
}
......
......@@ -15,6 +15,7 @@ import io.dataease.dto.chart.ChartViewDTO;
import io.dataease.dto.dataset.DataSetGroupDTO;
import io.dataease.dto.panel.PanelDesignDTO;
import io.dataease.dto.panel.PanelGroupDTO;
import io.dataease.exception.DataEaseException;
import io.dataease.i18n.Translator;
import io.dataease.service.chart.ChartViewService;
import io.dataease.service.sys.SysAuthService;
......@@ -128,7 +129,7 @@ public class PanelGroupService {
List<PanelGroup> checkResult = panelGroupMapper.selectByExample(groupExample);
if (CollectionUtils.isNotEmpty(checkResult)) {
throw new RuntimeException(Translator.get("i18n_same_folder_can_not_repeat"));
DataEaseException.throwException(Translator.get("i18n_same_folder_can_not_repeat"));
}
}
......
......@@ -9,6 +9,7 @@ import io.dataease.commons.utils.AuthUtils;
import io.dataease.commons.utils.BeanUtils;
import io.dataease.controller.request.panel.PanelTemplateRequest;
import io.dataease.dto.panel.PanelTemplateDTO;
import io.dataease.exception.DataEaseException;
import io.dataease.i18n.Translator;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
......@@ -71,7 +72,7 @@ public class PanelTemplateService {
request.setPid(request.getTemplateType());
String nameCheckResult = this.nameCheck(CommonConstants.OPT_TYPE.INSERT,request.getName(),request.getPid(),null);
if(CommonConstants.CHECK_RESULT.EXIST_ALL.equals(nameCheckResult)){
throw new RuntimeException(Translator.get("i18n_same_folder_can_not_repeat"));
DataEaseException.throwException(Translator.get("i18n_same_folder_can_not_repeat"));
}
}else{//模板插入 相同文件夹同名的模板进行覆盖(先删除)
PanelTemplateExample exampleDelete = new PanelTemplateExample();
......@@ -82,7 +83,7 @@ public class PanelTemplateService {
} else {
String nameCheckResult = this.nameCheck(CommonConstants.OPT_TYPE.UPDATE,request.getName(),request.getPid(),request.getId());
if(CommonConstants.CHECK_RESULT.EXIST_ALL.equals(nameCheckResult)){
throw new RuntimeException(Translator.get("i18n_same_folder_can_not_repeat"));
DataEaseException.throwException(Translator.get("i18n_same_folder_can_not_repeat"));
}
panelTemplateMapper.updateByPrimaryKeySelective(request);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论