use of com.webank.wedatasphere.qualitis.response.GeneralResponse 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.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class LoginServiceImpl method localLogin.
@Override
public GeneralResponse<?> localLogin(LocalLoginRequest request) throws LoginFailedException, UnExpectedRequestException {
// Check Arguments
checkRequest(request);
String username = request.getUsername();
String password = request.getPassword();
long currentLoginTime = System.currentTimeMillis();
User userInDb = userDao.findByUsername(username);
if (userInDb == null) {
throw new LoginFailedException("{&USER_NOT_EXIST}");
}
if (userInDb.getLockTime() != null && (currentLoginTime - userInDb.getLockTime()) / (1000 * 60) < 10) {
String lockTime = SDF.format(new Date(userInDb.getLockTime()));
LOGGER.info("Login locked. user: {}, lock time: {}", username, lockTime);
throw new LoginFailedException("{&LOGIN_LOCKED}" + lockTime);
}
if (localLogin(userInDb, password)) {
addToSession(username, httpRequest);
clearErrorLoginRecord(userInDb);
userDao.saveUser(userInDb);
LOGGER.info("Succeed to login. user: {}, current_user: {}", username, username);
return new GeneralResponse<>("200", "{&LOGIN_SUCCESS}", null);
} else {
// Login failed in first time.
if (userInDb.getLoginErrorTime() == null || userInDb.getLoginErrorCount() == null) {
userInDb.setLoginErrorTime(currentLoginTime);
userInDb.setLoginErrorCount(1);
} else {
// Check error count in 5 minutes decide to lock
boolean consecutiveError = (currentLoginTime - userInDb.getLoginErrorTime()) / (1000 * 60) < 5;
if (consecutiveError) {
userInDb.setLoginErrorCount(userInDb.getLoginErrorCount() + 1);
if (userInDb.getLoginErrorCount() >= 5) {
userInDb.setLockTime(currentLoginTime);
}
} else {
userInDb.setLoginErrorTime(currentLoginTime);
userInDb.setLoginErrorCount(1);
}
}
userDao.saveUser(userInDb);
throw new LoginFailedException("{&LOGIN_FAILED}" + (5 - userInDb.getLoginErrorCount()));
}
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class LoginServiceImpl method logout.
@Override
public GeneralResponse<?> logout(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException {
String username = HttpUtils.getUserName(httpServletRequest);
HttpSession session = httpServletRequest.getSession();
session.removeAttribute("permissions");
session.removeAttribute("user");
session.removeAttribute("proxyUser");
Cookie[] cookies = httpServletRequest.getCookies();
// Clear cookies.
if (cookies != null) {
for (Cookie cookie : cookies) {
String cookieName = cookie.getName();
if ("JSESSIONID".equals(cookieName)) {
cookieName = cookieName.replace("\r", "").replace("\n", "");
Cookie newCookie = new Cookie(cookieName, null);
newCookie.setSecure(true);
newCookie.setMaxAge(0);
newCookie.setPath("/");
httpServletResponse.addCookie(newCookie);
}
}
}
LOGGER.info("Succeed to logout, user: {}, current_user: {}", username, username);
String logoutUrl = frontEndConfig.getDomainName() + "/#/home";
httpServletResponse.sendRedirect(logoutUrl);
return new GeneralResponse<>("200", "{&LOGOUT_SUCCESSFULLY}", null);
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class ApplicationServiceImpl method filterStatusApplication.
@Override
public GeneralResponse<?> filterStatusApplication(FilterStatusRequest request) throws UnExpectedRequestException {
// Check arguments
FilterStatusRequest.checkRequest(request);
String userName = HttpUtils.getUserName(httpServletRequest);
if (request.getStatus() != null) {
LOGGER.info("User: {} wants to find applications with status: {}", userName, request.getStatus());
} else {
LOGGER.info("User: {} wants to find all applications", userName);
}
List<Application> applicationList;
Long total;
Integer page = request.getPage();
Integer size = request.getSize();
if (request.getStatus() == null || request.getStatus().intValue() == 0) {
// Paging find applications by user
long currentTimeUser = System.currentTimeMillis();
applicationList = applicationDao.findByCreateUser(userName, page, size);
LOGGER.info("timechecker find page application :" + (System.currentTimeMillis() - currentTimeUser));
long currentTimeCountUser = System.currentTimeMillis();
total = applicationDao.countByCreateUser(userName);
LOGGER.info("timechecker count application :" + (System.currentTimeMillis() - currentTimeCountUser));
} else {
// Paging find applications by user and status
applicationList = applicationDao.findByCreateUserAndStatus(userName, request.getStatus(), request.getCommentType(), page, size);
total = applicationDao.countByCreateUserAndStatus(userName, request.getStatus(), request.getCommentType());
}
long currentTimeResponse = System.currentTimeMillis();
GetAllResponse<ApplicationResponse> getAllResponse = new GetAllResponse<>();
List<ApplicationResponse> applicationResponses = new ArrayList<>();
for (Application application : applicationList) {
List<Task> tasks = taskDao.findByApplication(application);
ApplicationResponse response = new ApplicationResponse(application, tasks, httpServletRequest.getHeader("Content-Language"));
if (application.getCreateUser().equals(userName) || application.getExecuteUser().equals(userName)) {
response.setKillOption(true);
} else {
response.setKillOption(false);
}
applicationResponses.add(response);
}
getAllResponse.setData(applicationResponses);
getAllResponse.setTotal(total);
List<String> applicationIdList = getAllResponse.getData().stream().map(ApplicationResponse::getApplicationId).collect(Collectors.toList());
LOGGER.info("timechecker response :" + (System.currentTimeMillis() - currentTimeResponse));
LOGGER.info("Succeed to find applications. size: {}, id of applications: {}", total, applicationIdList);
return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_APPLICATIONS}", getAllResponse);
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class ApplicationServiceImpl method filterProjectApplication.
@Override
public GeneralResponse<?> filterProjectApplication(FilterProjectRequest request) throws UnExpectedRequestException {
// Check arguments
FilterProjectRequest.checkRequest(request);
Long userId = HttpUtils.getUserId(httpServletRequest);
User user = userDao.findById(userId);
Integer page = request.getPage();
Integer size = request.getSize();
Long projectId = request.getProjectId();
int total = applicationDao.countByCreateUserAndProject(user.getUserName(), projectId).intValue();
List<Application> applicationList = applicationDao.findByCreateUserAndProject(user.getUserName(), projectId, page, size);
GetAllResponse<ApplicationResponse> getAllResponse = new GetAllResponse<>();
List<ApplicationResponse> applicationResponses = new ArrayList<>();
for (Application application : applicationList) {
List<Task> tasks = taskDao.findByApplication(application);
ApplicationResponse response = new ApplicationResponse(application, tasks, httpServletRequest.getHeader("Content-Language"));
if (application.getCreateUser().equals(user.getUserName()) || application.getExecuteUser().equals(user.getUserName())) {
response.setKillOption(true);
} else {
response.setKillOption(false);
}
applicationResponses.add(response);
}
getAllResponse.setData(applicationResponses);
getAllResponse.setTotal(total);
List<String> applicationIdList = getAllResponse.getData().stream().map(ApplicationResponse::getApplicationId).collect(Collectors.toList());
LOGGER.info("Succeed to find applications. size: {}, id of applications: {}", total, applicationIdList);
return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_APPLICATIONS}", getAllResponse);
}
Aggregations