use of com.webank.wedatasphere.qualitis.entity.Department in project Qualitis by WeBankFinTech.
the class RuleMetricServiceImpl method queryRuleMetric.
@Override
public GeneralResponse<GetAllResponse<RuleMetricResponse>> queryRuleMetric(RuleMetricQueryRequest request) throws UnExpectedRequestException {
CommonChecker.checkObject(request, "Rule Metric query request");
if (StringUtils.isBlank(request.getSubSystemName())) {
request.setSubSystemName("");
}
if (StringUtils.isBlank(request.getRuleMetricName())) {
request.setRuleMetricName("%");
} else {
request.setRuleMetricName("%" + request.getRuleMetricName() + "%");
}
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 in query.");
ruleMetrics.addAll(ruleMetricDao.queryAllRuleMetrics(request.getSubSystemName(), request.getRuleMetricName(), request.getEnCode(), request.getType(), request.getAvailable(), request.getPage(), request.getSize()));
total = ruleMetricDao.countQueryAllRuleMetrics(request.getSubSystemName(), request.getRuleMetricName(), request.getEnCode(), request.getType(), request.getAvailable());
} 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.queryRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, null, request.getSubSystemName(), request.getRuleMetricName(), request.getEnCode(), request.getType(), request.getAvailable(), request.getPage(), request.getSize()));
total = ruleMetricDao.countQueryRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, null, request.getSubSystemName(), request.getRuleMetricName(), request.getEnCode(), request.getType(), request.getAvailable());
} else {
LOGGER.info("PROJECTOR will get rule metrics of department and own.");
List<Department> departments = new ArrayList<>();
departments.add(loginUser.getDepartment());
ruleMetrics.addAll(ruleMetricDao.queryRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, loginUser, request.getSubSystemName(), request.getRuleMetricName(), request.getEnCode(), request.getType(), request.getAvailable(), request.getPage(), request.getSize()));
total = ruleMetricDao.countQueryRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, loginUser, request.getSubSystemName(), request.getRuleMetricName(), request.getEnCode(), request.getType(), request.getAvailable());
}
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", "{&RULE_METRIC_QUERY_SUCCESS}", response);
}
use of com.webank.wedatasphere.qualitis.entity.Department in project Qualitis by WeBankFinTech.
the class UserServiceImpl method modifyDepartment.
@Override
public GeneralResponse<?> modifyDepartment(ModifyDepartmentRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
User userInDb = userDao.findById(request.getUserId());
if (null == userInDb) {
throw new UnExpectedRequestException("userId {&DOES_NOT_EXIST}");
}
// Find department by name.
Department departmentInDb = departmentDao.findByName(request.getDepartmentName());
if (null == departmentInDb) {
throw new UnExpectedRequestException("Department of " + request.getDepartmentName() + " {&DOES_NOT_EXIST}");
}
userInDb.setDepartment(departmentInDb);
// Save user
userDao.saveUser(userInDb);
LOGGER.info("Succeed to modify department, userId: {}, current_user: {}", userInDb.getId(), userInDb.getUserName());
return new GeneralResponse<>("200", "{&MODIFY_DEPARTMENT_SUCCESSFULLY}", null);
}
use of com.webank.wedatasphere.qualitis.entity.Department in project Qualitis by WeBankFinTech.
the class UserServiceImpl method addUser.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<AddUserResponse> addUser(UserAddRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
// Check existence of user by username
String username = request.getUsername();
User userInDb = userDao.findByUsername(username);
if (userInDb != null) {
throw new UnExpectedRequestException("username: " + username + " {&ALREADY_EXIST}");
}
// Generate random password and save user
User newUser = new User();
String password = RandomPasswordGenerator.generate(16);
String passwordEncoded = Sha256Encoder.encode(password);
newUser.setUserName(username);
newUser.setPassword(passwordEncoded);
newUser.setChineseName(request.getChineseName());
// Find department by department name
Department departmentInDb = departmentDao.findById(request.getDepartmentId());
if (null == departmentInDb) {
throw new UnExpectedRequestException("Department ID of " + request.getDepartmentId() + " {&DOES_NOT_EXIST}");
}
newUser.setDepartment(departmentInDb);
User savedUser = userDao.saveUser(newUser);
AddUserResponse addUserResponse = new AddUserResponse(savedUser, password);
LOGGER.info("Succeed to create user, response: {}, current_user: {}", addUserResponse, HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&CREATE_USER_SUCCESSFULLY}", addUserResponse);
}
use of com.webank.wedatasphere.qualitis.entity.Department in project Qualitis by WeBankFinTech.
the class DepartmentServiceImpl method addDepartment.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<DepartmentResponse> addDepartment(DepartmentAddRequest request) throws UnExpectedRequestException {
Department departmentInDb = departmentDao.findByName(request.getDepartmentName());
if (departmentInDb != null) {
LOGGER.error("Department already exist.");
throw new UnExpectedRequestException("Department {&ALREADY_EXIST}");
}
Department department = new Department();
department.setName(request.getDepartmentName());
Department savedDepartment = departmentDao.saveDepartment(department);
LOGGER.info("Succeed to create department, saved department info is : {}", savedDepartment.toString());
return new GeneralResponse<>("200", "{&ADD_DEPARTMENT_SUCCESSFULLY}", new DepartmentResponse(savedDepartment));
}
use of com.webank.wedatasphere.qualitis.entity.Department in project Qualitis by WeBankFinTech.
the class DepartmentServiceImpl method findAllDepartment.
@Override
public GeneralResponse<GetAllResponse<DepartmentResponse>> findAllDepartment(PageRequest request) throws UnExpectedRequestException {
PageRequest.checkRequest(request);
int page = request.getPage();
int size = request.getSize();
long total = departmentDao.countDepartment();
List<Department> departmentList = departmentDao.findAllDepartment(page, size);
List<DepartmentResponse> departmentResponses = new ArrayList<>(departmentList.size());
for (Department department : departmentList) {
departmentResponses.add(new DepartmentResponse(department));
}
GetAllResponse<DepartmentResponse> responses = new GetAllResponse<>();
responses.setData(departmentResponses);
responses.setTotal(total);
LOGGER.info("Succeed to find all departments, page: {}, size: {}, departments: {}", page, size, responses);
return new GeneralResponse("200", "{&GET_DEPARTMENT_SUCCESSFULLY}", responses);
}
Aggregations