use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class ProjectBatchServiceImpl method addRuleMetric.
private void addRuleMetric(ExcelRuleMetric excelRuleMetric, String userName) throws UnExpectedRequestException {
RuleMetric ruleMetricInDb = ruleMetricDao.findByEnCode(excelRuleMetric.getEnCode());
if (ruleMetricInDb != null) {
throw new UnExpectedRequestException("En code + [" + ruleMetricInDb.getEnCode() + "] + of metric {&ALREADY_EXIST}");
}
LOGGER.info("Start to add rule metric, user: [{}]", userName);
User loginUser = userDao.findByUsername(userName);
List<UserRole> userRoles = userRoleDao.findByUser(loginUser);
Integer roleType = roleService.getRoleType(userRoles);
RuleMetric newRuleMetric = new RuleMetric();
newRuleMetric.setCreateUser(userName);
newRuleMetric.setName(excelRuleMetric.getName());
newRuleMetric.setCnName(excelRuleMetric.getChName());
newRuleMetric.setEnCode(excelRuleMetric.getEnCode());
newRuleMetric.setMetricDesc(excelRuleMetric.getMetricDesc());
newRuleMetric.setCreateTime(ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date()));
RuleMetric savedRuleMetric = ruleMetricDao.add(newRuleMetric);
if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
LOGGER.info("First level(created by SYS_ADMIN) indicator will be created soon.");
savedRuleMetric.setLevel(RuleMetricLevelEnum.DEFAULT_METRIC.getCode());
} else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
LOGGER.info("Second level(created by DEPARTMENT_ADMIN) indicator will be created soon.");
savedRuleMetric.setLevel(RuleMetricLevelEnum.DEPARTMENT_METRIC.getCode());
for (UserRole temp : userRoles) {
Department department = temp.getRole().getDepartment();
if (department != null) {
RuleMetricDepartmentUser ruleMetricDepartmentUser = new RuleMetricDepartmentUser();
ruleMetricDepartmentUser.setDepartment(department);
ruleMetricDepartmentUser.setRuleMetric(savedRuleMetric);
ruleMetricDepartmentUserDao.add(ruleMetricDepartmentUser);
LOGGER.info("Succeed to save rule metric department user.");
}
}
} else {
LOGGER.info("Third level(created by PROJECTOR) indicator will be created soon.");
savedRuleMetric.setLevel(RuleMetricLevelEnum.PERSONAL_METRIC.getCode());
RuleMetricDepartmentUser ruleMetricDepartmentUser = new RuleMetricDepartmentUser();
ruleMetricDepartmentUser.setDepartment(loginUser.getDepartment());
ruleMetricDepartmentUser.setRuleMetric(savedRuleMetric);
ruleMetricDepartmentUser.setUser(loginUser);
ruleMetricDepartmentUserDao.add(ruleMetricDepartmentUser);
LOGGER.info("Succeed to save rule metric department user.");
}
savedRuleMetric.setBussCode(Integer.parseInt(excelRuleMetric.getDimension()));
savedRuleMetric.setCreateUser(userName);
savedRuleMetric.setFrequency(Integer.parseInt(excelRuleMetric.getFrequency()));
savedRuleMetric.setDevDepartmentName(excelRuleMetric.getDevDepartmentName());
savedRuleMetric.setOpsDepartmentName(excelRuleMetric.getOpsDepartmentName());
savedRuleMetric.setDepartmentName(excelRuleMetric.getDepartmentName());
savedRuleMetric.setSubSystemName(excelRuleMetric.getSubSystemName());
savedRuleMetric.setProductName(excelRuleMetric.getProductName());
savedRuleMetric.setFullCnName(excelRuleMetric.getFullCnName());
savedRuleMetric.setBussCustom(excelRuleMetric.getBussCustom());
savedRuleMetric.setAvailable(excelRuleMetric.getAvailable());
savedRuleMetric.setType(excelRuleMetric.getType());
ruleMetricDao.add(savedRuleMetric);
}
use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class RuleQueryServiceImpl method getColumnsByTableName.
@Override
public List<ColumnInfoDetail> getColumnsByTableName(String clusterName, Long datasourceId, String dbName, String tableName, String userName) throws UnExpectedRequestException, MetaDataAcquireFailedException {
List<ColumnInfoDetail> result = null;
User user = userDao.findByUsername(userName);
if (user == null) {
throw new UnExpectedRequestException(String.format("{&FAILED_TO_FIND_USER} %s", userName));
}
try {
if (StringUtils.isBlank(dbName)) {
List<Rule> rules = ruleDataSourceDao.findRuleByDataSource(clusterName, dbName, tableName, "%", userName);
if (rules == null || rules.isEmpty()) {
LOGGER.info("No rules for this datasource!");
return null;
}
LOGGER.info("Rules related with context service table: [{}] are: {}", tableName, rules.toArray());
String csId = rules.get(0).getCsId();
String nodeName = rules.get(0).getName();
GetUserTableByCsIdRequest getUserTableByCsIdRequest = new GetUserTableByCsIdRequest();
getUserTableByCsIdRequest.setClusterName(clusterName);
getUserTableByCsIdRequest.setLoginUser(userName);
getUserTableByCsIdRequest.setNodeName(nodeName);
getUserTableByCsIdRequest.setCsId(csId);
DataInfo<CsTableInfoDetail> csTableInfoDetails = metaDataClient.getTableByCsId(getUserTableByCsIdRequest);
if (csTableInfoDetails.getTotalCount() == 0) {
LOGGER.info("Cannot find context service table with existed rules!");
return null;
}
for (CsTableInfoDetail csTableInfoDetail : csTableInfoDetails.getContent()) {
if (csTableInfoDetail.getTableName().equals(tableName)) {
GetUserColumnByCsRequest getUserColumnByCsRequest = new GetUserColumnByCsRequest();
getUserColumnByCsRequest.setClusterName(clusterName);
getUserColumnByCsRequest.setContextKey(csTableInfoDetail.getContextKey());
getUserColumnByCsRequest.setCsId(csId);
getUserColumnByCsRequest.setLoginUser(userName);
result = metaDataClient.getColumnByCsId(getUserColumnByCsRequest).getContent();
setRuleCount(result, user.getId(), clusterName, dbName, tableName);
break;
} else {
continue;
}
}
} else {
if (datasourceId == null) {
result = metaDataClient.getColumnInfo(clusterName, dbName, tableName, userName);
} else {
result = metaDataClient.getColumnsByDataSource(clusterName, userName, datasourceId, dbName, tableName).getContent();
}
setRuleCount(result, user.getId(), clusterName, dbName, tableName);
}
LOGGER.info("Datasource table number of columns: {}", result == null ? 0 : result.size());
} catch (MetaDataAcquireFailedException e) {
LOGGER.error("Datasource colums info {&DOES_NOT_EXIST}. Exception: {}", e);
throw new MetaDataAcquireFailedException("Datasource colums info {&DOES_NOT_EXIST}. Exception: " + e.getMessage());
} catch (UnExpectedRequestException e) {
LOGGER.error("{&QUERY_PARAM_HAS_ERROR}. Exception: {}", e);
throw new UnExpectedRequestException("{&QUERY_PARAM_HAS_ERROR}. Exception: " + e.getMessage());
} catch (Exception e) {
LOGGER.error("exception: {}", e);
}
return result;
}
use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class RuleMetricServiceImpl method conditions.
@Override
public RuleMetricConditionResponse conditions() {
String userName = HttpUtils.getUserName(httpServletRequest);
LOGGER.info("Start to get rule metric condition, user: [{}]", userName);
User loginUser = userDao.findByUsername(userName);
List<UserRole> userRoles = userRoleDao.findByUser(loginUser);
Integer roleType = roleService.getRoleType(userRoles);
List<RuleMetric> ruleMetrics = new ArrayList<>();
if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
LOGGER.info("SYS_ADMIN will get all rule metrics with conditions.");
ruleMetrics.addAll(ruleMetricDao.findAllRuleMetrics(0, Integer.MAX_VALUE));
} else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
LOGGER.info("DEPARTMENT_ADMIN will get rule metrics of all management departments and all projectors.");
List<Department> departments = new ArrayList<>();
for (UserRole temp : userRoles) {
Department department = temp.getRole().getDepartment();
if (department != null) {
departments.add(department);
}
}
ruleMetrics.addAll(ruleMetricDao.findRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, null, 0, Integer.MAX_VALUE));
} else {
LOGGER.info("PROJECTOR will get rule metrics of department and own.");
List<Department> departments = new ArrayList<>();
departments.add(loginUser.getDepartment());
ruleMetrics.addAll(ruleMetricDao.findRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, loginUser, 0, Integer.MAX_VALUE));
}
Set<String> subSystemNameSet = ruleMetrics.stream().map(RuleMetric::getSubSystemName).filter(s -> StringUtils.isNotBlank(s)).collect(Collectors.toSet());
Set<RuleMetricTypeConfig> ruleMetricTypeConfigss = ruleMetricTypeConfigDao.findAllRuleMetricTypeConfig().stream().collect(Collectors.toSet());
Set<String> enCode = ruleMetrics.stream().map(RuleMetric::getEnCode).filter(s -> StringUtils.isNotBlank(s)).collect(Collectors.toSet());
RuleMetricConditionResponse response = new RuleMetricConditionResponse();
response.setSubSystemNameCondition(subSystemNameSet);
response.setRuleMetricType(ruleMetricTypeConfigss);
response.setEnCode(enCode);
return response;
}
use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class RuleMetricServiceImpl method deleteRuleMetric.
@Override
@Transactional(rollbackFor = { Exception.class, RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<RuleMetricResponse> deleteRuleMetric(long id) throws UnExpectedRequestException, PermissionDeniedRequestException {
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}");
}
String userName = HttpUtils.getUserName(httpServletRequest);
LOGGER.info("Start to delete rule metric, rule metric ID: [{}], user: [{}]", id, userName);
User loginUser = userDao.findByUsername(userName);
List<UserRole> userRoles = userRoleDao.findByUser(loginUser);
Integer roleType = roleService.getRoleType(userRoles);
if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
LOGGER.info("SYS_ADMIN will delete rule metric.");
RuleMetricDepartmentUser ruleMetricDepartmentUser = ruleMetricDepartmentUserDao.findByRuleMetric(ruleMetricInDb);
if (ruleMetricDepartmentUser != null) {
LOGGER.info("Rule metric[{}] will be delete.", ruleMetricInDb.toString());
ruleMetricDepartmentUserDao.delete(ruleMetricDepartmentUser);
}
} else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
LOGGER.info("DEPARTMENT_ADMIN will delete rule metric.");
if (ruleMetricInDb.getLevel().equals(RuleMetricLevelEnum.DEFAULT_METRIC.getCode())) {
throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
}
List<Department> managedDepartment = new ArrayList<>();
for (UserRole userRole : userRoles) {
Department department = userRole.getRole().getDepartment();
if (department != null) {
managedDepartment.add(department);
}
}
RuleMetricDepartmentUser ruleMetricDepartmentUser = ruleMetricDepartmentUserDao.findByRuleMetric(ruleMetricInDb);
if (ruleMetricDepartmentUser != null && managedDepartment.contains(ruleMetricDepartmentUser.getDepartment())) {
LOGGER.info("Rule metric[{}] will be delete.", ruleMetricInDb.toString());
ruleMetricDepartmentUserDao.delete(ruleMetricDepartmentUser);
} else {
throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
}
} else {
LOGGER.info("PROJECTOR will delete rule metric.");
if (!ruleMetricInDb.getLevel().equals(RuleMetricLevelEnum.PERSONAL_METRIC.getCode()) || !ruleMetricInDb.getCreateUser().equals(loginUser.getUserName())) {
throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
}
RuleMetricDepartmentUser ruleMetricDepartmentUser = ruleMetricDepartmentUserDao.findByRuleMetric(ruleMetricInDb);
if (ruleMetricDepartmentUser != null) {
LOGGER.info("Rule metric[{}] will be delete.", ruleMetricInDb.toString());
ruleMetricDepartmentUserDao.delete(ruleMetricDepartmentUser);
} else {
throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
}
}
ruleMetricDao.delete(ruleMetricInDb);
return new GeneralResponse<>("200", "{&DELETE_RULE_METRIC_SUCCESSFULLY}", null);
}
use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class RuleMetricServiceImpl method getAllRuleMetric.
@Override
public GeneralResponse<GetAllResponse<RuleMetricResponse>> getAllRuleMetric(PageRequest request) throws UnExpectedRequestException {
PageRequest.checkRequest(request);
String userName = HttpUtils.getUserName(httpServletRequest);
LOGGER.info("Start to get all rule metric, page request: [{}], user: [{}]", request.toString(), userName);
User loginUser = userDao.findByUsername(userName);
List<UserRole> userRoles = userRoleDao.findByUser(loginUser);
Integer roleType = roleService.getRoleType(userRoles);
List<RuleMetric> ruleMetrics = new ArrayList<>();
long total = 0;
if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
LOGGER.info("SYS_ADMIN will get all rule metrics.");
ruleMetrics.addAll(ruleMetricDao.findAllRuleMetrics(request.getPage(), request.getSize()));
total = ruleMetricDao.countAllRuleMetrics();
} else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
LOGGER.info("DEPARTMENT_ADMIN will get rule metrics of all management departments and all projectors.");
List<Department> departments = new ArrayList<>();
for (UserRole temp : userRoles) {
Department department = temp.getRole().getDepartment();
if (department != null) {
departments.add(department);
}
}
ruleMetrics.addAll(ruleMetricDao.findRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, null, request.getPage(), request.getSize()));
total = ruleMetricDao.countRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, null);
} else {
LOGGER.info("PROJECTOR will get rule metrics of department and own.");
List<Department> departments = new ArrayList<>();
departments.add(loginUser.getDepartment());
ruleMetrics.addAll(ruleMetricDao.findRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, loginUser, request.getPage(), request.getSize()));
total = ruleMetricDao.countRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, loginUser);
}
GetAllResponse<RuleMetricResponse> response = new GetAllResponse<>();
List<RuleMetricResponse> ruleMetricResponses = new ArrayList<>();
for (RuleMetric ruleMetric : ruleMetrics) {
ruleMetricResponses.add(new RuleMetricResponse(ruleMetric));
}
response.setData(ruleMetricResponses);
response.setTotal(total);
return new GeneralResponse<>("200", "{&GET_RULE_METRIC_SUCCESSFULLY}", response);
}
Aggregations