Search in sources :

Example 51 with User

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);
}
Also used : RuleTemplateResponse(com.webank.wedatasphere.qualitis.rule.response.RuleTemplateResponse) TemplateUser(com.webank.wedatasphere.qualitis.rule.entity.TemplateUser) User(com.webank.wedatasphere.qualitis.entity.User) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) TemplateDataSourceType(com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) Transactional(org.springframework.transaction.annotation.Transactional)

Example 52 with User

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;
}
Also used : User(com.webank.wedatasphere.qualitis.entity.User)

Example 53 with User

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;
}
Also used : User(com.webank.wedatasphere.qualitis.entity.User)

Example 54 with User

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();
}
Also used : Cookie(javax.servlet.http.Cookie) User(com.webank.wedatasphere.qualitis.entity.User) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) BodyReaderHttpServletRequestWrapper(com.webank.wedatasphere.qualitis.filter.BodyReaderHttpServletRequestWrapper) HttpSession(javax.servlet.http.HttpSession) ArrayList(java.util.ArrayList) RoleNotFoundException(javax.management.relation.RoleNotFoundException)

Aggregations

User (com.webank.wedatasphere.qualitis.entity.User)54 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)38 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)30 Transactional (org.springframework.transaction.annotation.Transactional)23 ArrayList (java.util.ArrayList)22 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)21 Department (com.webank.wedatasphere.qualitis.entity.Department)15 List (java.util.List)14 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)13 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)13 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)12 RuleMetricDepartmentUser (com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser)10 Project (com.webank.wedatasphere.qualitis.project.entity.Project)10 ProjectUser (com.webank.wedatasphere.qualitis.project.entity.ProjectUser)7 Application (com.webank.wedatasphere.qualitis.entity.Application)6 Task (com.webank.wedatasphere.qualitis.entity.Task)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 UserDao (com.webank.wedatasphere.qualitis.dao.UserDao)5 ApplicationResponse (com.webank.wedatasphere.qualitis.response.ApplicationResponse)5 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)5