use of com.webank.wedatasphere.qualitis.rule.request.DownloadRuleRequest in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method downloadRules.
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> downloadRules(DownloadRuleRequest request, HttpServletResponse response) throws UnExpectedRequestException, IOException, WriteExcelException, PermissionDeniedRequestException {
// Check Arguments
DownloadRuleRequest.checkRequest(request);
String loginUser = HttpUtils.getUserName(httpServletRequest);
Boolean projectAllRules = request.getProjectId() != null;
List<Rule> ruleLists;
if (projectAllRules) {
LOGGER.info("Downloading all rules of project. project id: {}", request.getProjectId());
Project project = projectDao.findById(request.getProjectId());
if (project == null) {
throw new UnExpectedRequestException("{&PROJECT_ID} {&DOES_NOT_EXIST}");
}
ruleLists = ruleDao.findByProject(project);
} else {
LOGGER.info("Downloading all rules. rule ids: {}", request.getRuleIds());
ruleLists = ruleDao.findByIds(request.getRuleIds());
List<Long> ruleIds = ruleLists.stream().map(Rule::getId).distinct().collect(Collectors.toList());
List<Long> notExistRules = request.getRuleIds().stream().filter(l -> !ruleIds.contains(l)).collect(Collectors.toList());
if (!notExistRules.isEmpty()) {
throw new UnExpectedRequestException("{&THE_IDS_OF_RULE}: " + notExistRules.toString() + " {&DOES_NOT_EXIST}");
}
}
if (ruleLists == null || ruleLists.isEmpty()) {
throw new UnExpectedRequestException("{&NO_RULE_CAN_DOWNLOAD}");
}
// Check permissions of project
List<Integer> permissions = new ArrayList<>();
permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
projectService.checkProjectPermission(ruleLists.iterator().next().getProject(), loginUser, permissions);
LOGGER.info("Succeed to find rules that will be downloaded. rule_ids: {}", ruleLists.stream().map(Rule::getId));
return downloadRulesReal(ruleLists, response, loginUser);
}
Aggregations