use of com.webank.wedatasphere.qualitis.request.PageRequest in project Qualitis by WeBankFinTech.
the class RuleQueryController method query.
@POST
@Path("query")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public GeneralResponse<?> query(RuleQueryRequest param, @Context HttpServletRequest request) {
if (param == null) {
param = new RuleQueryRequest();
}
// Get login user
param.setUser(HttpUtils.getUserName(request));
try {
PageRequest pageRequest = new PageRequest();
pageRequest.setPage(param.getPage());
pageRequest.setSize(param.getSize());
PageRequest.checkRequest(pageRequest);
DataInfo<RuleQueryDataSource> results = new DataInfo<>();
List<RuleQueryDataSource> ruleQueryDataSources = ruleQueryService.filter(pageRequest, param.getUser(), param.getCluster(), param.getDb(), param.getTable(), false);
results.setContent(ruleQueryDataSources);
List<RuleQueryDataSource> allRuleDataSource = ruleQueryService.filter(null, param.getUser(), param.getCluster(), param.getDb(), param.getTable(), true);
results.setTotalCount(allRuleDataSource == null ? 0 : allRuleDataSource.size());
LOG.info("[My DataSource] Query successfully. The number of results:{}", allRuleDataSource == null ? 0 : allRuleDataSource.size());
return new GeneralResponse<>("200", "{&QUERY_SUCCESSFULLY}", results);
} catch (Exception e) {
LOG.error("[My DataSource] Query failed, internal error.", e);
return new GeneralResponse<>("500", e.getMessage(), null);
}
}
use of com.webank.wedatasphere.qualitis.request.PageRequest in project Qualitis by WeBankFinTech.
the class ApplicationServiceImpl method uploadDataSourceAnalysisResult.
@Override
public GeneralResponse<?> uploadDataSourceAnalysisResult(UploadResultRequest request) throws UnExpectedRequestException, IOException {
// Login user permission.
Long userId = HttpUtils.getUserId(httpServletRequest);
User user = userDao.findById(userId);
if (user == null) {
throw new UnExpectedRequestException("User {&DOES_NOT_EXIST}");
}
UploadResultRequest.checkRequest(request);
List<ApplicationClusterResponse> responses = (List<ApplicationClusterResponse>) getDataSource(new PageRequest(0, Integer.MAX_VALUE)).getData();
List<String> tables = responses.stream().filter(cluster -> cluster.getClusterName().equals(request.getClusterName())).map(ApplicationClusterResponse::getDatabase).flatMap(database -> database.stream()).filter(databaseResponse -> databaseResponse.getDatabaseName().equals(request.getDatabaseName())).map(ApplicationDatabaseResponse::getTable).flatMap(table -> table.stream()).distinct().collect(Collectors.toList());
if (StringUtils.isNotBlank(request.getTableName())) {
tables.clear();
tables.add(request.getTableName());
}
LOGGER.info("Start to write excel");
StringBuffer fileName = new StringBuffer();
fileName.append(linkisConfig.getUploadTmpPath()).append(File.separator).append(user.getUserName()).append("_").append(request.getClusterName()).append("_").append(request.getDatabaseName()).append("_").append(UUID.randomUUID().toString()).append(ExcelTypeEnum.XLSX.getValue());
File tmpFile = new File(fileName.toString());
writeExcelFile(tmpFile, tables, request);
// Upload to HDFS
ClusterInfo clusterInfo = clusterInfoDao.findByClusterName(request.getClusterName());
if (clusterInfo == null) {
throw new UnExpectedRequestException("Cluster info " + "[" + request.getClusterName() + "]" + "{&DOES_NOT_EXIST}");
}
// send request to get dbs
String url = UriBuilder.fromUri(clusterInfo.getLinkisAddress()).path(linkisConfig.getPrefix()).path(linkisConfig.getUpload()).toString();
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost(url);
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
multipartEntityBuilder.setContentType(ContentType.MULTIPART_FORM_DATA);
multipartEntityBuilder.setCharset(Charset.forName("UTF-8"));
if (clusterInfo.getClusterType().endsWith(LINKIS_ONE_VERSION)) {
multipartEntityBuilder.addTextBody("path", linkisConfig.getUploadPrefix() + LINKIS_ONE_UPLOAD_PREFIX + request.getHdfsPath());
} else {
multipartEntityBuilder.addTextBody("path", linkisConfig.getUploadPrefix() + request.getHdfsPath());
}
multipartEntityBuilder.addBinaryBody("file", tmpFile);
httppost.addHeader("Token-User", user.getUserName());
httppost.addHeader("Token-Code", clusterInfo.getLinkisToken());
httppost.setEntity(multipartEntityBuilder.build());
CloseableHttpResponse response = null;
try {
response = httpclient.execute(httppost);
} catch (IOException e) {
throw new UnExpectedRequestException("{&FAILED_TO_CALL_UPLOAD_API}");
}
int code = response.getStatusLine().getStatusCode();
response.close();
if (code != HttpStatus.SC_OK) {
throw new UnExpectedRequestException("{&FAILED_TO_CALL_UPLOAD_API}");
}
boolean tmpDeleteFlag = tmpFile.delete();
LOGGER.info("Delete tmp excel: " + tmpDeleteFlag);
return new GeneralResponse<>(code + "", "{&SUCCESS_TO_UPLOAD_ANALYSIS_EXCEL}", code);
}
use of com.webank.wedatasphere.qualitis.request.PageRequest in project Qualitis by WeBankFinTech.
the class RuleMetricServiceImpl method download.
@Override
public GeneralResponse<?> download(DownloadRuleMetricRequest request, HttpServletResponse response) throws UnExpectedRequestException, IOException, WriteExcelException, PermissionDeniedRequestException {
// Check rule metric IDs permission.
PageRequest pageRequest = new PageRequest(0, Integer.MAX_VALUE);
List<RuleMetricResponse> ownRuleMetric = getAllRuleMetric(pageRequest).getData().getData().stream().collect(Collectors.toList());
if (ownRuleMetric.size() <= 0 || ownRuleMetric.size() >= MAX_RULE_METRIC_COUNT) {
throw new UnExpectedRequestException("The number of metrics is illegal");
}
List<Long> downloadIds = request.getRuleMetricIds();
List<Long> ownIds = ownRuleMetric.stream().map(RuleMetricResponse::getId).collect(Collectors.toList());
if (ownIds.containsAll(downloadIds)) {
List<RuleMetricResponse> downloadRuleMetric = ownRuleMetric.stream().filter(ruleMetricResponse -> downloadIds.contains(ruleMetricResponse.getId())).collect(Collectors.toList());
List<ExcelRuleMetric> excelRuleMetrics = new ArrayList<>(downloadRuleMetric.size());
for (RuleMetricResponse ruleMetricResponse : downloadRuleMetric) {
ExcelRuleMetric excelRuleMetric = new ExcelRuleMetric();
excelRuleMetric.setName(ruleMetricResponse.getName());
excelRuleMetric.setChName(ruleMetricResponse.getCnName());
excelRuleMetric.setMetricDesc(ruleMetricResponse.getMetricDesc());
int bussCode = ruleMetricResponse.getBussCode();
excelRuleMetric.setDimension(bussCode + "");
if (RuleMetricBussCodeEnum.SUBSYSTEM.getCode().equals(bussCode)) {
excelRuleMetric.setFullCnName(ruleMetricResponse.getFullCnName());
excelRuleMetric.setSubSystemName(ruleMetricResponse.getSubSystemName());
excelRuleMetric.setSubSystemId(String.valueOf(ruleMetricResponse.getSubSystemId()));
} else if (RuleMetricBussCodeEnum.PRODUCT.getCode().equals(bussCode)) {
excelRuleMetric.setProductId(ruleMetricResponse.getProductId());
excelRuleMetric.setProductName(ruleMetricResponse.getProductName());
} else if (RuleMetricBussCodeEnum.CUSTOM.getCode().equals(bussCode)) {
excelRuleMetric.setBussCustom(ruleMetricResponse.getBussCustom());
}
excelRuleMetric.setFrequency(String.valueOf(ruleMetricResponse.getFrequency()));
excelRuleMetric.setDevDepartmentName(ruleMetricResponse.getDevDepartmentName());
excelRuleMetric.setOpsDepartmentName(ruleMetricResponse.getOpsDepartmentName());
excelRuleMetric.setDepartmentCode(ruleMetricResponse.getDepartmentCode());
excelRuleMetric.setDepartmentName(ruleMetricResponse.getDepartmentName());
excelRuleMetric.setAvailable(ruleMetricResponse.getAvailable());
excelRuleMetric.setEnCode(ruleMetricResponse.getEnCode());
excelRuleMetric.setType(ruleMetricResponse.getType());
excelRuleMetrics.add(excelRuleMetric);
}
String fileName = "batch_metrics_export_" + FILE_DATE_FORMATTER.format(new Date());
fileName = URLEncoder.encode(fileName, "UTF-8");
response.setContentType("application/octet-stream");
response.addHeader("Content-Disposition", "attachment;filename*=UTF-8''" + fileName);
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
OutputStream outputStream = response.getOutputStream();
writeExcelToOutput(excelRuleMetrics, outputStream);
outputStream.flush();
} else {
throw new PermissionDeniedRequestException("HAS_NO_PERMISSION_TO_ACCESS", 403);
}
LOGGER.info("Succeed to download all rule metrics in type of excel");
return null;
}
use of com.webank.wedatasphere.qualitis.request.PageRequest in project Qualitis by WeBankFinTech.
the class ProjectUserController method getUser.
@GET
@Path("/user")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public GeneralResponse<?> getUser(@Context HttpServletRequest httpServletRequest) throws UnExpectedRequestException {
try {
Long userId = HttpUtils.getUserId(httpServletRequest);
PageRequest pageRequest = new PageRequest(0, Integer.MAX_VALUE);
return projectUserService.getAllUsers(pageRequest, userId);
} catch (UnExpectedRequestException e) {
LOGGER.error(e.getMessage(), e);
throw e;
} catch (Exception e) {
LOGGER.error("Failed to find users, caused by system error: {}", e.getMessage());
return new GeneralResponse<>("500", "{&FAILED_TO_FIND_ALL_USERS}", null);
}
}
Aggregations