use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class OuterExecutionServiceImpl method dataSourceExecution.
@Override
public GeneralResponse<?> dataSourceExecution(DataSourceExecutionRequest request) throws UnExpectedRequestException, PermissionDeniedRequestException {
LOGGER.info("Execute application by datasource. cluster: {}, database: {}, table: {}", request.getCluster(), request.getDatabase(), request.getTable());
// Check Arguments.
DataSourceExecutionRequest.checkRequest(request);
String loginUser = getLoginUser(httpServletRequest, request.getCreateUser(), request.getAsync());
// Find all rule datasources by user.
List<RuleDataSource> ruleDataSources = new ArrayList<>();
ruleDataSources.addAll(ruleDataSourceDao.findDatasourcesByUser(loginUser, request.getCluster(), request.getDatabase(), request.getTable()));
List<Rule> rules = ruleDataSources.stream().filter(r -> r.getClusterName().equals(request.getCluster()) && r.getDbName().equals(request.getDatabase()) && r.getTableName().equals(request.getTable())).map(RuleDataSource::getRule).distinct().filter(rule -> {
if (!request.getCrossTable()) {
return rule.getRuleDataSources().size() == 1;
}
return true;
}).collect(Collectors.toList());
if (CollectionUtils.isEmpty(rules)) {
throw new UnExpectedRequestException("{&NO_RULE_CAN_BE_EXECUTED}");
}
checkPermissionCreateUserProxyExecuteUser(request.getCreateUser(), request.getExecutionUser());
ApplicationProjectResponse applicationProjectResponse = new ApplicationProjectResponse();
List<ApplicationSubmitRequest> applicationSubmitRequests = new ArrayList<>();
StringBuffer partition = new StringBuffer();
StringBuffer runDate = new StringBuffer();
Map<String, String> execParamMap = new HashMap<>(5);
parseExecParams(partition, runDate, request.getExecutionParam(), execParamMap);
List<Project> projects = rules.stream().map(Rule::getProject).distinct().collect(Collectors.toList());
for (Project projectInDb : projects) {
// Check permissions of project
List<Integer> permissions = new ArrayList<>();
permissions.add(ProjectUserPermissionEnum.OPERATOR.getCode());
projectService.checkProjectPermission(projectInDb, loginUser, permissions);
List<Rule> currentRules = rules.stream().filter(rule -> rule.getProject().getId().equals(projectInDb.getId())).collect(Collectors.toList());
List<RuleGroup> currentRuleGroups = currentRules.stream().map(Rule::getRuleGroup).distinct().collect(Collectors.toList());
for (RuleGroup ruleGroup : currentRuleGroups) {
List<Rule> currentRulesOfGroup = currentRules.stream().filter(rule -> rule.getRuleGroup().getRuleGroupName().equals(ruleGroup.getRuleGroupName())).distinct().collect(Collectors.toList());
List<Long> currentRuleIds = currentRulesOfGroup.stream().map(Rule::getId).distinct().collect(Collectors.toList());
LOGGER.info("Succeed to find current rules of one group with datasource. rule_id: {}", currentRuleIds);
// Dynamic partition.
try {
submitRulesWithDynamicPartition(applicationSubmitRequests, projectInDb.getId(), ruleGroup.getId(), rules, currentRuleIds, request.getExecutionUser(), request.getDyNamicPartition(), request.getClusterName(), partition, request.getDyNamicPartitionPrefix());
} catch (ResourceAccessException e) {
// Record submit failed applicatoin.
generateAbnormalApplicationInfo(projectInDb.getId(), ruleGroup.getId(), request.getCreateUser(), request.getExecutionUser(), new Date(), InvokeTypeEnum.BDP_CLIENT_API_INVOKE.getCode(), partition.toString(), request.getStartupParamName(), request.getExecutionParam(), e, ApplicationCommentEnum.METADATA_ISSUES.getCode(), ApplicationStatusEnum.TASK_SUBMIT_FAILED.getCode(), rules);
LOGGER.error("One group execution[id={}] of the datasource execution start failed!", ruleGroup.getId());
} catch (NoPartitionException e) {
// Record submit failed applicatoin.
generateAbnormalApplicationInfo(projectInDb.getId(), ruleGroup.getId(), request.getCreateUser(), request.getExecutionUser(), new Date(), InvokeTypeEnum.BDP_CLIENT_API_INVOKE.getCode(), partition.toString(), request.getStartupParamName(), request.getExecutionParam(), e, ApplicationCommentEnum.METADATA_ISSUES.getCode(), ApplicationStatusEnum.TASK_SUBMIT_FAILED.getCode(), rules);
LOGGER.error("One group execution[id={}] of the datasource execution start failed!", ruleGroup.getId());
} catch (Exception e) {
// Record submit failed applicatoin.
generateAbnormalApplicationInfo(projectInDb.getId(), ruleGroup.getId(), request.getCreateUser(), request.getExecutionUser(), new Date(), InvokeTypeEnum.BDP_CLIENT_API_INVOKE.getCode(), partition.toString(), request.getStartupParamName(), request.getExecutionParam(), e, ApplicationCommentEnum.UNKNOWN_ERROR_ISSUES.getCode(), ApplicationStatusEnum.TASK_SUBMIT_FAILED.getCode(), rules);
LOGGER.error("One group execution[id={}] of the datasource execution start failed!", ruleGroup.getId());
}
if (CollectionUtils.isNotEmpty(currentRuleIds)) {
applicationSubmitRequests.add(new ApplicationSubmitRequest(request.getJobId(), projectInDb.getId(), ruleGroup.getId(), currentRuleIds, partition));
}
}
projectEventService.record(projectInDb.getId(), loginUser, "submit datasource execution", "rule name[" + Arrays.toString(rules.stream().filter(rule -> rule.getProject().getId().equals(projectInDb.getId())).toArray()) + "].", EventTypeEnum.SUBMIT_PROJECT.getCode());
}
GeneralResponse<ApplicationTaskSimpleResponse> generalResponse;
for (ApplicationSubmitRequest applicationSubmitRequest : applicationSubmitRequests) {
if (StringUtils.isNotBlank(request.getJobId())) {
applicationSubmitRequest.setJobId(request.getJobId());
}
generalResponse = (GeneralResponse<ApplicationTaskSimpleResponse>) outerExecutionService.submitRules(applicationSubmitRequest.getRuleIds(), applicationSubmitRequest.getPartition(), loginUser, request.getExecutionUser(), DEFAULT_NODE_NAME, applicationSubmitRequest.getProjectId(), applicationSubmitRequest.getRuleGroupId(), request.getStartupParamName(), request.getClusterName(), request.getSetFlag(), execParamMap, request.getExecutionParam(), runDate, InvokeTypeEnum.BDP_CLIENT_API_INVOKE.getCode());
applicationProjectResponse.getApplicationTaskSimpleResponses().add(generalResponse.getData());
}
return new GeneralResponse<>("200", "{&SUCCEED_TO_DISPATCH_TASK}", applicationProjectResponse);
}
use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method uploadRulesReal.
private GeneralResponse<?> uploadRulesReal(InputStream fileInputStream, String fileName, String userName, Long projectId, boolean aomp) throws UnExpectedRequestException, ClusterInfoNotConfigException, ParseException, SemanticException, MetaDataAcquireFailedException, TaskNotExistException, IOException, PermissionDeniedRequestException {
if (userName == null) {
return new GeneralResponse<>("401", "{&PLEASE_LOGIN}", null);
}
// Check suffix name of file
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 + "]", 422);
}
ExcelRuleListener excelRuleListener = readExcel(fileInputStream);
if (excelRuleListener.getCustomExcelContent().isEmpty() && excelRuleListener.getTemplateExcelContent().isEmpty() && excelRuleListener.getMultiTemplateExcelContent().isEmpty() && excelRuleListener.getTemplateFileExcelContent().isEmpty()) {
throw new UnExpectedRequestException("{&FILE_CAN_NOT_BE_EMPTY_OR_FILE_CAN_NOT_BE_RECOGNIZED}", 422);
}
// Record project event.
List<String> ruleNames = new ArrayList<>(excelRuleListener.getTemplateExcelContent().keySet().size() + excelRuleListener.getCustomExcelContent().keySet().size() + excelRuleListener.getTemplateFileExcelContent().keySet().size() + excelRuleListener.getMultiTemplateExcelContent().keySet().size());
ruleNames.addAll(excelRuleListener.getCustomExcelContent().keySet());
ruleNames.addAll(excelRuleListener.getTemplateExcelContent().keySet());
ruleNames.addAll(excelRuleListener.getTemplateFileExcelContent().keySet());
ruleNames.addAll(excelRuleListener.getMultiTemplateExcelContent().keySet());
if (projectId != null) {
Project projectInDb = projectDao.findById(projectId);
if (projectInDb == null) {
throw new UnExpectedRequestException("{&PROJECT_ID} {&DOES_NOT_EXIST}");
}
// Check permissions of project
List<Integer> permissions = new ArrayList<>();
permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
projectService.checkProjectPermission(projectInDb, userName, permissions);
getAndSaveRule(excelRuleListener.getTemplateExcelContent(), excelRuleListener.getCustomExcelContent(), excelRuleListener.getMultiTemplateExcelContent(), excelRuleListener.getTemplateFileExcelContent(), projectInDb, userName, aomp);
// projectEventService.record(projectInDb.getId(), userName, "upload", "[" + Arrays.toString(ruleNames.toArray()) + "].", EventTypeEnum.MODIFY_PROJECT.getCode());
} else {
// All three rules are derived from the same project.
String projectName = "";
if (CollectionUtils.isNotEmpty(excelRuleListener.getTemplateExcelContent().keySet())) {
projectName = excelRuleListener.getTemplateExcelContent().values().iterator().next().iterator().next().getProjectName();
} else if (CollectionUtils.isNotEmpty(excelRuleListener.getCustomExcelContent().keySet())) {
projectName = excelRuleListener.getCustomExcelContent().values().iterator().next().iterator().next().getProjectName();
} else if (CollectionUtils.isNotEmpty(excelRuleListener.getMultiTemplateExcelContent().keySet())) {
projectName = excelRuleListener.getMultiTemplateExcelContent().values().iterator().next().iterator().next().getProjectName();
} else if (CollectionUtils.isNotEmpty(excelRuleListener.getTemplateFileExcelContent().keySet())) {
projectName = excelRuleListener.getTemplateFileExcelContent().values().iterator().next().iterator().next().getProjectName();
}
Project project = projectDao.findByNameAndCreateUser(projectName, userName);
if (project == null) {
// Auto create project for aomp rules upload.
AddProjectRequest addProjectRequest = new AddProjectRequest();
String currentProjectName = "AOMP_AUTO_PROJECT_" + System.currentTimeMillis();
addProjectRequest.setProjectName(currentProjectName);
addProjectRequest.setDescription("This is for aomp");
User user = userDao.findByUsername(userName);
Long userId = user.getId();
projectService.addProject(addProjectRequest, userId);
project = projectDao.findByNameAndCreateUser(currentProjectName, userName);
}
getAndSaveRule(excelRuleListener.getTemplateExcelContent(), excelRuleListener.getCustomExcelContent(), excelRuleListener.getMultiTemplateExcelContent(), excelRuleListener.getTemplateFileExcelContent(), project, userName, aomp);
// projectEventService.record(project.getId(), userName, "upload", "[" + Arrays.toString(ruleNames.toArray()) + "].", EventTypeEnum.MODIFY_PROJECT.getCode());
}
fileInputStream.close();
return new GeneralResponse<>("200", "{&SUCCEED_TO_UPLOAD_FILE}", null);
}
use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class RuleTemplateServiceImpl method modifyRuleTemplate.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public RuleTemplateResponse modifyRuleTemplate(ModifyRuleTemplateRequest request) throws UnExpectedRequestException, PermissionDeniedRequestException {
AddRuleTemplateRequest addRuleTemplateRequest = ModifyRuleTemplateRequest.checkRequest(request);
// Check template existence
Template templateInDb = checkRuleTemplate(request.getTemplateId());
// Check user info.
User userInDb = userDao.findById(HttpUtils.getUserId(httpServletRequest));
List<UserRole> userRoles = userRoleDao.findByUser(userInDb);
Integer roleType = roleService.getRoleType(userRoles);
if (roleType.equals(RoleDefaultTypeEnum.PROJECTOR.getCode())) {
LOGGER.info("The projector is going to modify template.");
if (templateInDb.getLevel().intValue() != RuleTemplateLevelEnum.PERSONAL_TEMPLATE.getCode()) {
throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
}
if (!userInDb.equals(templateInDb.getCreateUser())) {
throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
}
} else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
LOGGER.info("The department admin is going to modify template.");
if (templateInDb.getLevel().intValue() == RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode()) {
throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
}
List<User> createUsers = new ArrayList<>();
for (UserRole userRole : userRoles) {
Department department = userRole.getRole().getDepartment();
if (department != null) {
List<User> userList = userDao.findByDepartment(department);
createUsers.addAll(userList);
}
}
if (!createUsers.contains(templateInDb.getCreateUser())) {
throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
}
} else {
LOGGER.info("The system admin is going to modify template.");
}
// delete output meta
templateOutputMetaService.deleteByTemplate(templateInDb);
// delete mid_table input meta
templateMidTableInputMetaService.deleteByTemplate(templateInDb);
// delete statistics input meta
templateStatisticsInputMetaService.deleteByTemplate(templateInDb);
// delete template type relationship
templateDataSourceTypeDao.deleteByTemplate(templateInDb);
// Save template.
if (!templateInDb.getName().equals(request.getTemplateName())) {
checkTemplateName(request.getTemplateName());
}
templateInDb.setName(request.getTemplateName());
templateInDb.setClusterNum(request.getClusterNum());
templateInDb.setDbNum(request.getDbNum());
templateInDb.setTableNum(request.getTableNum());
templateInDb.setFieldNum(request.getFieldNum());
templateInDb.setActionType(request.getActionType());
templateInDb.setMidTableAction(request.getMidTableAction());
templateInDb.setSaveMidTable(request.getSaveMidTable());
templateInDb.setShowSql(request.getMidTableAction());
templateInDb.setTemplateType(request.getTemplateType());
templateInDb.setModifyUser(userInDb);
Template savedTemplate = ruleTemplateDao.saveTemplate(templateInDb);
List<TemplateDataSourceType> templateDataSourceTypes = templateDataSourceTypeDao.findByTemplate(savedTemplate);
List<Integer> templateDataSourceTypeIntegers = templateDataSourceTypes.stream().map(TemplateDataSourceType::getDataSourceTypeId).collect(Collectors.toList());
for (Integer type : request.getDatasourceType()) {
if (!templateDataSourceTypeIntegers.contains(type)) {
TemplateDataSourceType templateDataSourceType = new TemplateDataSourceType(type, savedTemplate);
templateDataSourceTypeDao.save(templateDataSourceType);
}
}
LOGGER.info("Succeed to save rule template, template_id: {}", savedTemplate.getId());
// Save template info.
createAndSaveTemplateInfo(savedTemplate, addRuleTemplateRequest);
return new RuleTemplateResponse(savedTemplate);
}
use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class RuleTemplateServiceImpl method getDefaultRuleTemplate.
@Override
public GeneralResponse<GetAllResponse<RuleTemplateResponse>> getDefaultRuleTemplate(TemplatePageRequest request) throws UnExpectedRequestException {
// Check Arguments
TemplatePageRequest.checkRequest(request);
int size = request.getSize();
int page = request.getPage();
String dataSourceType = request.getDataSourceType();
Integer dataSourceTypeCode = TemplateDataSourceTypeEnum.getCode(dataSourceType);
List<User> users = new ArrayList<>();
List<Template> templates;
List<Department> departments = new ArrayList<>();
long total = 0;
User userInDb = userDao.findById(HttpUtils.getUserId(httpServletRequest));
List<UserRole> userRoles = userRoleDao.findByUser(userInDb);
Integer roleType = roleService.getRoleType(userRoles);
if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
templates = ruleTemplateDao.findAllDefaultTemplate(page, size);
total = ruleTemplateDao.countAllDefaultTemplate();
} else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
for (UserRole userRole : userRoles) {
Department department = userRole.getRole().getDepartment();
if (department != null) {
departments.add(department);
List<User> userList = userDao.findByDepartment(department);
users.addAll(userList);
}
}
templates = ruleTemplateDao.findTemplates(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode(), RuleTemplateTypeEnum.SINGLE_SOURCE_TEMPLATE.getCode(), departments.size() == 0 ? null : departments, users.size() == 0 ? null : users, dataSourceTypeCode, page, size);
total = ruleTemplateDao.countTemplates(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode(), RuleTemplateTypeEnum.SINGLE_SOURCE_TEMPLATE.getCode(), departments.size() == 0 ? null : departments, users.size() == 0 ? null : users, dataSourceTypeCode);
} else {
Department department = userInDb.getDepartment();
if (department != null) {
departments.add(department);
}
users.add(userInDb);
templates = ruleTemplateDao.findTemplates(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode(), RuleTemplateTypeEnum.SINGLE_SOURCE_TEMPLATE.getCode(), departments.size() == 0 ? null : departments, users.size() == 0 ? null : users, dataSourceTypeCode, page, size);
total = ruleTemplateDao.countTemplates(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode(), RuleTemplateTypeEnum.SINGLE_SOURCE_TEMPLATE.getCode(), departments.size() == 0 ? null : departments, users.size() == 0 ? null : users, dataSourceTypeCode);
}
GetAllResponse<RuleTemplateResponse> response = new GetAllResponse<>();
response.setTotal(total);
List<RuleTemplateResponse> responseList = new ArrayList<>();
for (Template template : templates) {
RuleTemplateResponse ruleTemplateResponse = new RuleTemplateResponse(template);
List<Integer> types = templateDataSourceTypeDao.findByTemplate(template).stream().map(TemplateDataSourceType::getDataSourceTypeId).collect(Collectors.toList());
ruleTemplateResponse.setDatasourceType(types);
responseList.add(ruleTemplateResponse);
}
response.setData(responseList);
LOGGER.info("Succeed to find default rule_template. response: {}", response);
return new GeneralResponse<>("200", "{&GET_RULE_TEMPLATE_SUCCESSFULLY}", response);
}
use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class RuleTemplateServiceImpl method getMultiRuleTemplate.
/**
* Paging get template
* @param request
* @return
*/
@Override
public GeneralResponse<GetAllResponse<RuleTemplateResponse>> getMultiRuleTemplate(TemplatePageRequest request) throws UnExpectedRequestException {
// Check Arguments
TemplatePageRequest.checkRequest(request);
int size = request.getSize();
int page = request.getPage();
String dataSourceType = request.getDataSourceType();
Integer dataSourceTypeCode = TemplateDataSourceTypeEnum.getCode(dataSourceType);
List<User> users = new ArrayList<>(1);
List<Department> departments = new ArrayList<>(1);
List<Template> templates;
long total = 0;
User userInDb = userDao.findById(HttpUtils.getUserId(httpServletRequest));
List<UserRole> userRoles = userRoleDao.findByUser(userInDb);
Integer roleType = roleService.getRoleType(userRoles);
if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
templates = ruleTemplateDao.findAllMultiTemplate(dataSourceTypeCode, page, size);
total = ruleTemplateDao.countAllMultiTemplate(dataSourceTypeCode);
} else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
for (UserRole userRole : userRoles) {
Department department = userRole.getRole().getDepartment();
if (department != null) {
departments.add(department);
List<User> userList = userDao.findByDepartment(department);
users.addAll(userList);
}
}
templates = ruleTemplateDao.findTemplates(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode(), RuleTemplateTypeEnum.MULTI_SOURCE_TEMPLATE.getCode(), departments.size() == 0 ? null : departments, users.size() == 0 ? null : users, dataSourceTypeCode, page, size);
total = ruleTemplateDao.countTemplates(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode(), RuleTemplateTypeEnum.MULTI_SOURCE_TEMPLATE.getCode(), departments.size() == 0 ? null : departments, users.size() == 0 ? null : users, dataSourceTypeCode);
} else {
Department department = userInDb.getDepartment();
if (department != null) {
departments.add(department);
}
users.add(userInDb);
templates = ruleTemplateDao.findTemplates(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode(), RuleTemplateTypeEnum.MULTI_SOURCE_TEMPLATE.getCode(), departments.size() == 0 ? null : departments, users.size() == 0 ? null : users, dataSourceTypeCode, page, size);
total = ruleTemplateDao.countTemplates(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode(), RuleTemplateTypeEnum.MULTI_SOURCE_TEMPLATE.getCode(), departments.size() == 0 ? null : departments, users.size() == 0 ? null : users, dataSourceTypeCode);
}
GetAllResponse<RuleTemplateResponse> response = new GetAllResponse<>();
response.setTotal(total);
List<RuleTemplateResponse> responseList = new ArrayList<>();
for (Template template : templates) {
RuleTemplateResponse ruleTemplateResponse = new RuleTemplateResponse(template);
List<Integer> types = templateDataSourceTypeDao.findByTemplate(template).stream().map(TemplateDataSourceType::getDataSourceTypeId).collect(Collectors.toList());
ruleTemplateResponse.setDatasourceType(types);
responseList.add(ruleTemplateResponse);
}
response.setData(responseList);
LOGGER.info("Succeed to find multi rule_template. response: {}", response);
return new GeneralResponse<>("200", "{&GET_MULTI_RULE_TEMPLATE_SUCCESSFULLY}", response);
}
Aggregations