use of com.webank.wedatasphere.qualitis.entity.RuleMetric 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.RuleMetric 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.RuleMetric 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);
}
use of com.webank.wedatasphere.qualitis.entity.RuleMetric in project Qualitis by WeBankFinTech.
the class AddFileRuleRequestBuilder method addRuleMetricWithCheck.
@Override
public AddRequestBuilder addRuleMetricWithCheck(String ruleMetricName, boolean deleteFailCheckResult, boolean uploadRuleMetricValue, boolean uploadAbnormalValue) throws UnExpectedRequestException {
RuleMetric ruleMetricInDb = ruleMetricDao.findByName(ruleMetricName);
if (ruleMetricInDb != null) {
setRuleMetricEnCode(ruleMetricInDb.getEnCode());
setUploadAbnormalValue(uploadAbnormalValue);
setUploadRuleMetricValue(uploadRuleMetricValue);
setDeleteFailCheckResult(deleteFailCheckResult);
return this;
}
String[] infos = ruleMetricName.split(SpecCharEnum.BOTTOM_BAR.getValue());
if (infos.length != FOUR) {
throw new UnExpectedRequestException("The metric name does not meet specifications");
}
String en = infos[2];
List<String> existRuleMetricNames = addFileRuleRequest.getRuleMetricNamesForBdpClient();
if (CollectionUtils.isNotEmpty(existRuleMetricNames)) {
existRuleMetricNames.add(ruleMetricName);
} else {
List<String> ruleMetricNames = new ArrayList<>(1);
ruleMetricNames.add(ruleMetricName);
addFileRuleRequest.setRuleMetricNamesForBdpClient(ruleMetricNames);
}
setRuleMetricEnCode(en);
setUploadAbnormalValue(uploadAbnormalValue);
setUploadRuleMetricValue(uploadRuleMetricValue);
setDeleteFailCheckResult(deleteFailCheckResult);
return this;
}
use of com.webank.wedatasphere.qualitis.entity.RuleMetric in project Qualitis by WeBankFinTech.
the class AddRuleRequestBuilder method addRuleMetric.
@Override
public AddRequestBuilder addRuleMetric(String ruleMetricName) throws UnExpectedRequestException {
RuleMetric ruleMetricInDb = ruleMetricDao.findByName(ruleMetricName);
if (ruleMetricInDb != null) {
setRuleMetricEnCode(ruleMetricInDb.getEnCode());
return this;
}
String[] infos = ruleMetricName.split(SpecCharEnum.BOTTOM_BAR.getValue());
if (infos.length != FOUR) {
throw new UnExpectedRequestException("The metric name does not meet specifications");
}
String en = infos[2];
List<String> ruleMetricNames = new ArrayList<>(1);
ruleMetricNames.add(ruleMetricName);
addRuleRequest.setRuleMetricNamesForBdpClient(ruleMetricNames);
setRuleMetricEnCode(en);
return this;
}
Aggregations