use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.
the class RuleMetricServiceImpl method upload.
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> upload(InputStream fileInputStream, FormDataContentDisposition fileDisposition) throws UnExpectedRequestException, IOException {
// Check Arguments
if (fileInputStream == null || fileDisposition == null) {
throw new UnExpectedRequestException("{&FILE_CAN_NOT_BE_NULL_OR_EMPTY}");
}
// Check suffix name of file
String fileName = fileDisposition.getFileName();
String suffixName = fileName.substring(fileName.lastIndexOf('.'));
if (!suffixName.equals(SUPPORT_EXCEL_SUFFIX_NAME)) {
throw new UnExpectedRequestException("{&DO_NOT_SUPPORT_SUFFIX_NAME}: [" + suffixName + "]. {&ONLY_SUPPORT} [" + SUPPORT_EXCEL_SUFFIX_NAME + "]");
}
String userName = HttpUtils.getUserName(httpServletRequest);
LOGGER.info(userName + " start to upload rule metrics.");
ExcelRuleMetricListener listener = new ExcelRuleMetricListener();
List<ExcelRuleMetric> excelRuleMetrics = listener.getRuleMetricContent();
ExcelReader excelReader = new ExcelReader(fileInputStream, null, listener);
List<Sheet> sheets = excelReader.getSheets();
for (Sheet sheet : sheets) {
if (sheet.getSheetName().equals(ExcelSheetName.RULE_METRIC_NAME)) {
sheet.setClazz(ExcelRuleMetric.class);
sheet.setHeadLineMun(1);
excelReader.read(sheet);
}
}
if (CollectionUtils.isEmpty(excelRuleMetrics)) {
throw new UnExpectedRequestException("{&FILE_CAN_NOT_BE_EMPTY_OR_FILE_CAN_NOT_BE_RECOGNIZED}");
}
try {
for (ExcelRuleMetric excelRuleMetric : excelRuleMetrics) {
AddRuleMetricRequest addRuleMetricRequest = new AddRuleMetricRequest();
addRuleMetric(addRuleMetricRequest);
}
LOGGER.info("Succeed to add all rule metrics");
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
} finally {
fileInputStream.close();
}
return new GeneralResponse<>("200", "{&FAILED_TO_UPLOAD_RULE_METRIC}", null);
}
use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.
the class RuleMetricServiceImpl method getRulesByRuleMetric.
@Override
public DataInfo<HiveRuleDetail> getRulesByRuleMetric(long id, int page, int size) throws UnExpectedRequestException {
DataInfo<HiveRuleDetail> dataInfo = new DataInfo<>();
if (id <= 0) {
throw new UnExpectedRequestException("{&REQUEST_CAN_NOT_BE_NULL}");
}
// Check rule metric existence.
RuleMetric ruleMetricInDb = ruleMetricDao.findById(id);
if (ruleMetricInDb == null) {
throw new UnExpectedRequestException("Rule Metric ID [" + id + "] {&DOES_NOT_EXIST}");
}
List<Long> ruleIds = taskResultDao.findRuleByRuleMetric(ruleMetricInDb.getId(), page, size).stream().distinct().collect(Collectors.toList());
int total = taskResultDao.countRuleByRuleMetric(ruleMetricInDb.getId());
List<HiveRuleDetail> result = new ArrayList<>(ruleIds.size());
for (Long ruleId : ruleIds) {
Rule ruleInDb = ruleDao.findById(ruleId);
if (ruleInDb == null) {
total--;
continue;
}
List<Long> ruleMetricIds = ruleInDb.getAlarmConfigs().stream().map(AlarmConfig::getRuleMetric).filter(ruleMetric -> ruleMetric != null).map(RuleMetric::getId).collect(Collectors.toList());
if (ruleInDb != null && ruleMetricIds.contains(id)) {
HiveRuleDetail hiveRuleDetail = new HiveRuleDetail(ruleInDb);
result.add(hiveRuleDetail);
}
}
dataInfo.setContent(result);
dataInfo.setTotalCount(total);
return dataInfo;
}
use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.
the class MetaDataController method getTablesByDataSource.
@GET
@Path("data_source/tables")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public GeneralResponse<GetAllResponse<TableInfoDetail>> getTablesByDataSource(@QueryParam("clusterName") String clusterName, @QueryParam("proxyUser") String proxyUser, @QueryParam("dataSourceId") Long dataSourceId, @QueryParam("dbName") String dbName) {
try {
if (dataSourceId == null || StringUtils.isBlank(dbName) || StringUtils.isBlank(clusterName)) {
throw new UnExpectedRequestException("Request " + "{&CAN_NOT_BE_NULL_OR_EMPTY}");
}
Map response = metaDataService.getTablesByDataSource(clusterName, proxyUser, dataSourceId, dbName);
GetAllResponse allResponse = new GetAllResponse();
List<String> tables = (List<String>) response.get("tables");
List<TableInfoDetail> tableInfoDetails = new ArrayList<>(CollectionUtils.isEmpty(tables) ? 0 : tables.size());
for (String table : tables) {
TableInfoDetail tableInfoDetail = new TableInfoDetail(table);
tableInfoDetails.add(tableInfoDetail);
}
allResponse.setTotal(CollectionUtils.isEmpty(tableInfoDetails) ? 0 : tableInfoDetails.size());
allResponse.setData(tableInfoDetails);
return new GeneralResponse<>("200", "{&GET_TABLE_SUCCESSFULLY}", allResponse);
} catch (MetaDataAcquireFailedException e) {
LOGGER.error(e.getMessage(), e);
return new GeneralResponse<>("500", e.getMessage(), null);
} catch (UnExpectedRequestException e) {
LOGGER.error(e.getMessage(), e);
return new GeneralResponse<>("500", e.getMessage(), null);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
return new GeneralResponse<>("500", "{&FAILED_TO_GET_TABLE_BY_DATABASE}", null);
}
}
use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.
the class PermissionServiceImpl method addPermission.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<PermissionResponse> addPermission(AddPermissionRequest request) throws UnExpectedRequestException {
// Check Arguments
AddPermissionRequest.checkRequest(request);
String method = request.getMethod().trim();
String url = request.getUrl().trim();
// Find permission by method and url
Permission permissionInDb = permissionDao.findByMethodAndUrl(method, url);
if (permissionInDb != null) {
throw new UnExpectedRequestException("{&METHOD_AND_URL_ALREADY_EXIST}, request: " + request);
}
Permission newPermission = new Permission();
newPermission.setMethod(method);
newPermission.setUrl(url);
Permission savedPermission = permissionDao.savePermission(newPermission);
LOGGER.info("Succeed to add permission, id: {}, method: {}, url: {}, current_user: {}", savedPermission.getId(), method, url, HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&ADD_PERMISSION_SUCCESSFULLY}", new PermissionResponse(savedPermission));
}
use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.
the class PermissionServiceImpl method deletePermission.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deletePermission(DeletePermissionRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
Long permissionId = request.getPermissionId();
// Find permissions by permission id
Permission permissionInDb = permissionDao.findById(permissionId);
if (permissionInDb == null) {
throw new UnExpectedRequestException("{&PERMISSION_ID_NOT_EXIST}, request: " + request);
}
List<RolePermission> rolePermissionsInDb = rolePermissionDao.findByPermission(permissionInDb);
if (null != rolePermissionsInDb && !rolePermissionsInDb.isEmpty()) {
throw new UnExpectedRequestException("{&DELETE_ERROR_ROLE_PERMISSION_HAS_FOREIGN_KEY}");
}
List<UserSpecPermission> userSpecPermissionsInDb = userSpecPermissionDao.findByPermission(permissionInDb);
if (null != userSpecPermissionsInDb && !userSpecPermissionsInDb.isEmpty()) {
throw new UnExpectedRequestException("{&DELETE_ERROR_USER_SPEC_PERMISSION_HAS_FOREIGN_KEY}");
}
permissionDao.deletePermission(permissionInDb);
LOGGER.info("Succeed to delete permission, permissionId: {}, method: {}, url: {}, current_user: {}", permissionId, permissionInDb.getMethod(), permissionInDb.getUrl(), HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&DELETE_PERMISSION_SUCCESSFULLY}", null);
}
Aggregations