Search in sources :

Example 51 with GeneralResponse

use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.

the class RolePermissionServiceImpl method modifyRolePermission.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> modifyRolePermission(ModifyRolePermissionRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    // Check existence of role permission
    String uuid = request.getUuid();
    RolePermission rolePermissionInDb = rolePermissionDao.findByUuid(uuid);
    if (rolePermissionInDb == null) {
        throw new UnExpectedRequestException("role permission id {&DOES_NOT_EXIST}, request: " + request);
    }
    LOGGER.info("Succeed to find role_permission, uuid: {}, role_id: {}, permission_id: {}, current_user: {}", uuid, rolePermissionInDb.getRole().getId(), rolePermissionInDb.getPermission().getId(), HttpUtils.getUserName(httpServletRequest));
    long roleId = request.getRoleId();
    long permissionId = request.getPermissionId();
    Role roleInDb = roleDao.findById(roleId);
    if (roleInDb == null) {
        throw new UnExpectedRequestException("role id {&DOES_NOT_EXIST}, request: " + request);
    }
    Permission permissionInDb = permissionDao.findById(permissionId);
    if (permissionInDb == null) {
        throw new UnExpectedRequestException("permission id {&DOES_NOT_EXIST}, request: " + request);
    }
    RolePermission roleIdAndPermissionIdInDb = rolePermissionDao.findByRoleAndPermission(roleInDb, permissionInDb);
    if (roleIdAndPermissionIdInDb != null) {
        throw new UnExpectedRequestException("role and permission {&ALREADY_EXIST}, request: " + request);
    }
    // Save role permission
    rolePermissionInDb.setRole(roleInDb);
    rolePermissionInDb.setPermission(permissionInDb);
    RolePermission savedRolePermission = rolePermissionDao.saveRolePermission(rolePermissionInDb);
    LOGGER.info("Succeed to modify role_permission, uuid: {}, role_id: {}, permission_id: {}, current_user: {}", uuid, savedRolePermission.getRole().getId(), savedRolePermission.getPermission().getId(), HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&MODIFY_ROLE_PERMISSION_SUCCESSFULLY}", null);
}
Also used : Role(com.webank.wedatasphere.qualitis.entity.Role) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Permission(com.webank.wedatasphere.qualitis.entity.Permission) RolePermission(com.webank.wedatasphere.qualitis.entity.RolePermission) RolePermission(com.webank.wedatasphere.qualitis.entity.RolePermission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 52 with GeneralResponse

use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.

the class RoleServiceImpl method getRoleByUser.

@Override
public GeneralResponse<?> getRoleByUser() {
    Long userId;
    String username = null;
    // Get current userId
    userId = HttpUtils.getUserId(httpServletRequest);
    username = HttpUtils.getUserName(httpServletRequest);
    User userInDb = userDao.findById(userId);
    // Find user role by user
    List<UserRole> userRoles = userRoleDao.findByUser(userInDb);
    // Get all roles of user
    List<String> roleNames = userRoles.stream().map(userRole -> userRole.getRole().getName()).collect(Collectors.toList());
    UserAndRoleResponse response = new UserAndRoleResponse();
    response.setRoles(roleNames);
    response.setUsername(username);
    HttpSession session = httpServletRequest.getSession();
    response.setLoginRandom((Integer) session.getAttribute("loginRandom"));
    LOGGER.info("Succeed to get role of user, {}  role: {}, current_user: {}", username, roleNames.toString(), username);
    return new GeneralResponse<>("200", "{&GET_ROLE_SUCCESSFULLY}", response);
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) LoggerFactory(org.slf4j.LoggerFactory) UserRoleDao(com.webank.wedatasphere.qualitis.dao.UserRoleDao) Autowired(org.springframework.beans.factory.annotation.Autowired) RoleResponse(com.webank.wedatasphere.qualitis.response.RoleResponse) ArrayList(java.util.ArrayList) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpUtils(com.webank.wedatasphere.qualitis.util.HttpUtils) Service(org.springframework.stereotype.Service) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) DepartmentDao(com.webank.wedatasphere.qualitis.dao.DepartmentDao) RoleService(com.webank.wedatasphere.qualitis.service.RoleService) RoleRequest(com.webank.wedatasphere.qualitis.request.role.RoleRequest) HttpSession(javax.servlet.http.HttpSession) RoleAddRequest(com.webank.wedatasphere.qualitis.request.role.RoleAddRequest) Logger(org.slf4j.Logger) Context(javax.ws.rs.core.Context) RoleModifyRequest(com.webank.wedatasphere.qualitis.request.role.RoleModifyRequest) PageRequest(com.webank.wedatasphere.qualitis.request.PageRequest) UserAndRoleResponse(com.webank.wedatasphere.qualitis.response.UserAndRoleResponse) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) List(java.util.List) RoleDao(com.webank.wedatasphere.qualitis.dao.RoleDao) com.webank.wedatasphere.qualitis.entity(com.webank.wedatasphere.qualitis.entity) RolePermissionDao(com.webank.wedatasphere.qualitis.dao.RolePermissionDao) UserDao(com.webank.wedatasphere.qualitis.dao.UserDao) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RoleDefaultTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.RoleDefaultTypeEnum) BodyReaderHttpServletRequestWrapper(com.webank.wedatasphere.qualitis.filter.BodyReaderHttpServletRequestWrapper) Transactional(org.springframework.transaction.annotation.Transactional) UserAndRoleResponse(com.webank.wedatasphere.qualitis.response.UserAndRoleResponse) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) HttpSession(javax.servlet.http.HttpSession)

Example 53 with GeneralResponse

use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.

the class TransferUserServiceImpl method transferUser.

@Override
public GeneralResponse<?> transferUser(String user) throws UnExpectedRequestException {
    User userInDb = userDao.findByUsername(user);
    if (userInDb == null) {
        throw new UnExpectedRequestException("ProxyUser: " + user + " {&DOES_NOT_EXIST}");
    }
    Map<String, Object> userMap = ImmutableMap.of("userId", userInDb.getId(), "username", userInDb.getUserName());
    HttpSession httpSession = httpServletRequest.getSession();
    httpSession.setAttribute("proxyUser", userMap);
    return new GeneralResponse<>("200", "{&SUCCEED_TO_TRANSFER_TO_PROXYUSER}", null);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) User(com.webank.wedatasphere.qualitis.entity.User) HttpSession(javax.servlet.http.HttpSession)

Example 54 with GeneralResponse

use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.

the class UserProxyUserServiceImpl method deleteUserProxyUser.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteUserProxyUser(DeleteUserProxyUserRequest request) throws UnExpectedRequestException {
    // Check Arguments
    DeleteUserProxyUserRequest.checkRequest(request);
    // Find user proxy user by id
    UserProxyUser userProxyUserInDb = userProxyUserRepository.findById(request.getUserProxyUserId()).orElse(null);
    if (userProxyUserInDb == null) {
        throw new UnExpectedRequestException("User proxy user id {&DOES_NOT_EXIST}, request: " + request);
    }
    userProxyUserRepository.delete(userProxyUserInDb);
    LOGGER.info("Succeed to delete user proxy user. user_proxy_user_id: {}", request.getUserProxyUserId());
    return new GeneralResponse<>("200", "{&SUCCEED_TO_DELETE_USER_PROXY_USER}", null);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) UserProxyUser(com.webank.wedatasphere.qualitis.entity.UserProxyUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 55 with GeneralResponse

use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.

the class UserRoleServiceImpl method deleteUserRole.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteUserRole(DeleteUserRoleRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    // Check existence of user role
    String uuid = request.getUuid();
    UserRole userRoleInDb = userRoleDao.findByUuid(uuid);
    if (userRoleInDb == null) {
        throw new UnExpectedRequestException("user role id {&DOES_NOT_EXIST}, request: " + request);
    }
    // Delete user role
    userRoleDao.deleteUserRole(userRoleInDb);
    LOGGER.info("Succeed to delete user_role. uuid: {}, current_user: {}", request.getUuid(), HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&DELETE_USER_ROLE_SUCCESSFULLY}", null);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)146 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)96 Transactional (org.springframework.transaction.annotation.Transactional)49 ArrayList (java.util.ArrayList)48 User (com.webank.wedatasphere.qualitis.entity.User)40 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)30 Project (com.webank.wedatasphere.qualitis.project.entity.Project)28 Map (java.util.Map)27 ClusterInfo (com.webank.wedatasphere.qualitis.entity.ClusterInfo)26 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)24 List (java.util.List)22 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)21 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)17 IOException (java.io.IOException)16 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)15 Date (java.util.Date)15 Task (com.webank.wedatasphere.qualitis.entity.Task)14 JSONObject (org.json.JSONObject)14 HttpEntity (org.springframework.http.HttpEntity)14 HttpHeaders (org.springframework.http.HttpHeaders)14