refactor: 去掉 unused imports

This commit is contained in:
taojinlong
2021-06-24 14:01:40 +08:00
51 changed files with 767 additions and 720 deletions

View File

@@ -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();

View File

@@ -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();

View File

@@ -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;

View File

@@ -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();
}
}

View File

@@ -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;";
}
}
}
}

View 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);
}

View File

@@ -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");
}
}

View File

@@ -1,22 +1,8 @@
package io.dataease.job.sechedule;
import io.dataease.commons.utils.LogUtil;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.TriggerKey;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.SimpleTrigger;
import org.quartz.TriggerBuilder;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.CronExpression;
import org.quartz.JobExecutionContext;
import io.dataease.exception.DataEaseException;
import org.quartz.*;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@@ -111,7 +97,7 @@ public class ScheduleManager {
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
throw new RuntimeException(e);
DataEaseException.throwException(e);
}
}
@@ -141,7 +127,7 @@ public class ScheduleManager {
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
throw new RuntimeException(e);
DataEaseException.throwException(e);
}
}
@@ -202,7 +188,7 @@ public class ScheduleManager {
// addJob(jobName, jobGroupName, triggerName, triggerGroupName, jobClass, cron);
/** 方式二 先删除然后在创建一个新的Job */
} catch (Exception e) {
throw new RuntimeException(e);
DataEaseException.throwException(e);
}
}
@@ -254,7 +240,7 @@ public class ScheduleManager {
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
throw new RuntimeException(e);
DataEaseException.throwException(e);
}
}
@@ -286,7 +272,7 @@ public class ScheduleManager {
}
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
throw new RuntimeException(e);
DataEaseException.throwException(e);
}
}
@@ -310,7 +296,7 @@ public class ScheduleManager {
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
throw new RuntimeException(e);
DataEaseException.throwException(e);
}
}
@@ -320,7 +306,7 @@ public class ScheduleManager {
sched.start();
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
throw new RuntimeException(e);
DataEaseException.throwException(e);
}
}
@@ -332,7 +318,7 @@ public class ScheduleManager {
}
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
throw new RuntimeException(e);
DataEaseException.throwException(e);
}
}
@@ -431,7 +417,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();

View File

@@ -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());
}
}
}

View File

@@ -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();

View File

@@ -21,6 +21,7 @@ import io.dataease.datasource.provider.JdbcProvider;
import io.dataease.datasource.provider.ProviderFactory;
import io.dataease.datasource.request.DatasourceRequest;
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;
@@ -460,7 +461,7 @@ public class ExtractDataService {
if (jobStatus.getStatusDescription().equals("Finished")) {
return;
} else {
throw new Exception(jobStatus.getLoggingString());
DataEaseException.throwException((jobStatus.getLoggingString()));
}
}

View File

@@ -10,6 +10,7 @@ import io.dataease.commons.utils.TreeUtils;
import io.dataease.controller.request.panel.PanelGroupRequest;
import io.dataease.dto.chart.ChartViewDTO;
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;
@@ -119,7 +120,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"));
}
}

View File

@@ -41,13 +41,16 @@ public class PanelSubjectService {
public List<PanelSubject> query(PanelSubjectRequest request){
PanelSubjectExample example = new PanelSubjectExample();
return panelSubjectMapper.selectByExampleWithBLOBs(null);
example.setOrderByClause( "create_time asc");
return panelSubjectMapper.selectByExampleWithBLOBs(example);
}
public List querySubjectWithGroup(PanelSubjectRequest request){
List result = new ArrayList();
int pageSize = 4;
List<PanelSubject> allInfo = panelSubjectMapper.selectByExampleWithBLOBs(null);
PanelSubjectExample example = new PanelSubjectExample();
example.setOrderByClause( "create_time asc");
List<PanelSubject> allInfo = panelSubjectMapper.selectByExampleWithBLOBs(example);
for(int i =0;i<allInfo.size();i=i+pageSize){
List<PanelSubject> tmp = allInfo.subList(i,i+pageSize<allInfo.size()?i+pageSize:allInfo.size());
result.add(tmp);

View File

@@ -8,6 +8,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;
@@ -70,7 +71,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();
@@ -81,7 +82,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);
}