use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class RuleTemplateServiceImpl method addRuleTemplate.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class }, propagation = Propagation.REQUIRED)
public RuleTemplateResponse addRuleTemplate(AddRuleTemplateRequest request) throws UnExpectedRequestException {
AddRuleTemplateRequest.checkRequest(request, false);
LOGGER.info("Add default rule template request detail: {}", request.toString());
// Save template.
checkTemplateName(request.getTemplateName());
Template newTemplate = new Template();
newTemplate.setName(request.getTemplateName());
newTemplate.setClusterNum(request.getClusterNum());
newTemplate.setDbNum(request.getDbNum());
newTemplate.setTableNum(request.getTableNum());
newTemplate.setFieldNum(request.getFieldNum());
newTemplate.setActionType(request.getActionType());
newTemplate.setMidTableAction(request.getMidTableAction());
newTemplate.setSaveMidTable(request.getSaveMidTable());
newTemplate.setShowSql(request.getMidTableAction());
newTemplate.setTemplateType(request.getTemplateType());
newTemplate.setImportExportName(UuidGenerator.generate());
// Save create user info.
User userInDb = userDao.findById(HttpUtils.getUserId(httpServletRequest));
newTemplate.setCreateUser(userInDb);
Template savedTemplate = ruleTemplateDao.saveTemplate(newTemplate);
for (Integer type : request.getDatasourceType()) {
TemplateDataSourceType templateDataSourceType = new TemplateDataSourceType(type, savedTemplate);
templateDataSourceTypeDao.save(templateDataSourceType);
}
LOGGER.info("Succeed to save rule template, template_id: {}", savedTemplate.getId());
// Determine the template level and save association table.
List<UserRole> userRoles = userRoleDao.findByUser(userInDb);
Integer roleType = roleService.getRoleType(userRoles);
// Save department template
if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
savedTemplate.setLevel(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode());
} else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
savedTemplate.setLevel(RuleTemplateLevelEnum.DEPARTMENT_TEMPLATE.getCode());
saveTemplateDepartment(ruleTemplateDao.saveTemplate(savedTemplate), userRoles);
} else {
savedTemplate.setLevel(RuleTemplateLevelEnum.PERSONAL_TEMPLATE.getCode());
saveTemplateUser(userInDb, ruleTemplateDao.saveTemplate(savedTemplate));
}
// Save template info.
createAndSaveTemplateInfo(savedTemplate, request);
return new RuleTemplateResponse(savedTemplate);
}
use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class UserRoleDaoTest method saveUser.
private User saveUser() {
// 保存是否成功
User user = new User();
user.setChineseName("xxx");
user.setUserName("xxx");
user.setPassword("xxx");
User saveUser = userDao.saveUser(user);
assertTrue(saveUser.getId() != 0);
return saveUser;
}
use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class UserSpecPermissionDaoTest method saveUser.
private User saveUser() {
// 保存是否成功
User user = new User();
user.setChineseName("xxx");
user.setUserName("xxx");
user.setPassword("xxx");
User saveUser = userDao.saveUser(user);
assertTrue(saveUser.getId() != 0);
return saveUser;
}
use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class QualitisHttpSessionUserInterceptor method addUserToSession.
@Override
public void addUserToSession(String userName, HttpServletRequest request) {
// 查询数据库,看用户是否存在
User userInDb = userDao.findByUsername(userName);
if (userInDb != null) {
// 放入session
LOGGER.info("User: {} succeed to login", userName);
loginService.addToSession(userName, request);
} else {
// 自动创建用户
LOGGER.warn("user: {}, do not exist, trying to create user", userName);
try {
userService.autoAddUser(userName);
loginService.addToSession(userName, request);
} catch (RoleNotFoundException e) {
LOGGER.error("Failed to auto add user, cause by: Failed to get role [PROJECTOR]", e);
}
}
HttpSession session = request.getSession();
Cookie cookie = new Cookie("JSESSIONID", session.getId());
cookie.setSecure(true);
cookie.setPath("/");
HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(request) {
@Override
public Cookie[] getCookies() {
List<Cookie> cookieList = new ArrayList<>();
cookieList.add(cookie);
final Cookie[] cookies = (Cookie[]) cookieList.toArray();
return cookies;
}
};
request = (HttpServletRequest) requestWrapper.getRequest();
}
Aggregations