use of com.webank.wedatasphere.qualitis.entity.Department in project Qualitis by WeBankFinTech.
the class DepartmentServiceImpl method deleteDepartment.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteDepartment(Long departmentId) throws UnExpectedRequestException {
if (departmentId == null) {
throw new UnExpectedRequestException("department id {&CAN_NOT_BE_NULL_OR_EMPTY}");
}
Department departmentInDb = departmentDao.findById(departmentId);
if (departmentInDb == null) {
LOGGER.error("Department donot exist.");
throw new UnExpectedRequestException("Department {&DOES_NOT_EXIST}");
}
// Check user exists.
checkUser(departmentInDb);
// Check role exists.
checkRole(departmentInDb);
departmentDao.deleteDepartment(departmentInDb);
LOGGER.info("Succeed to delete department, saved department id is : {}", departmentId);
return new GeneralResponse<>("200", "{&DELETE_DEPARTMENT_SUCCESSFULLY}", null);
}
use of com.webank.wedatasphere.qualitis.entity.Department in project Qualitis by WeBankFinTech.
the class DepartmentServiceImpl method modifyDepartment.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> modifyDepartment(DepartmentModifyRequest request) throws UnExpectedRequestException {
request.checkRequest();
Department departmentInDb = departmentDao.findById(request.getDepartmentId());
if (departmentInDb == null) {
LOGGER.error("Department donot exist.");
throw new UnExpectedRequestException("Department {&DOES_NOT_EXIST}");
}
departmentInDb.setName(request.getDepartmentName());
Department savedDepartment = departmentDao.saveDepartment(departmentInDb);
LOGGER.info("Succeed to modify department, saved department info is : {}", savedDepartment.toString());
return new GeneralResponse<>("200", "{&MODIFY_DEPARTMENT_SUCCESSFULLY}", null);
}
use of com.webank.wedatasphere.qualitis.entity.Department 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.Department 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.Department 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);
}
Aggregations