use of com.webank.wedatasphere.qualitis.request.FilterDataSourceRequest in project Qualitis by WeBankFinTech.
the class ApplicationServiceImpl method filterDataSourceApplication.
@Override
public GeneralResponse<?> filterDataSourceApplication(FilterDataSourceRequest request) throws UnExpectedRequestException {
// Check arguments
FilterDataSourceRequest.checkRequest(request);
Integer page = request.getPage();
Integer size = request.getSize();
String clusterName = request.getClusterName();
String databaseName = StringUtils.isEmpty(request.getDatabaseName()) ? "" : request.getDatabaseName();
String tableName = StringUtils.isEmpty(request.getTableName()) ? "" : request.getTableName();
Long userId = HttpUtils.getUserId(httpServletRequest);
User user = userDao.findById(userId);
List<TaskDataSource> taskDataSources;
long total;
// Find datasource by user
taskDataSources = taskDataSourceDao.findByCreateUserAndDatasource(user.getUserName(), clusterName, databaseName, tableName, page, size);
total = taskDataSourceDao.countByCreateUserAndDatasource(user.getUserName(), clusterName, databaseName, tableName);
List<Application> applicationList = taskDataSources.stream().map(jobDataSource -> jobDataSource.getTask().getApplication()).collect(Collectors.toList());
GetAllResponse<ApplicationResponse> getAllResponse = new GetAllResponse<>();
List<ApplicationResponse> applicationResponses = new ArrayList<>();
for (Application application : applicationList) {
List<Task> tasks = taskDao.findByApplication(application);
ApplicationResponse response = new ApplicationResponse(application, tasks, httpServletRequest.getHeader("Content-Language"));
if (application.getCreateUser().equals(user.getUserName()) || application.getExecuteUser().equals(user.getUserName())) {
response.setKillOption(true);
} else {
response.setKillOption(false);
}
applicationResponses.add(response);
}
getAllResponse.setData(applicationResponses);
getAllResponse.setTotal(total);
List<String> applicationIdList = getAllResponse.getData().stream().map(ApplicationResponse::getApplicationId).collect(Collectors.toList());
LOGGER.info("Succeed to find applications. size: {}, id of applications: {}", total, applicationIdList);
return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_APPLICATIONS}", getAllResponse);
}
Aggregations