Search in sources :

Example 86 with UnExpectedRequestException

use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.

the class RoleServiceImpl method addRole.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<RoleResponse> addRole(RoleAddRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    // Check existence of role by role name
    String roleName = request.getRoleName();
    Role roleInDb = roleDao.findByRoleName(roleName);
    if (roleInDb != null) {
        throw new UnExpectedRequestException("role name {&ALREADY_EXIST}, request: " + request);
    }
    // Save new role
    Role newRole = new Role();
    newRole.setName(roleName);
    if (request.getDepartmentName() != null) {
        Department departmentInDb = departmentDao.findByName(request.getDepartmentName());
        if (departmentInDb == null) {
            throw new UnExpectedRequestException("department {&DOES_NOT_EXIST}, name: " + request.getDepartmentName());
        }
        LOGGER.info("Succeed to find department. Name: " + departmentInDb.getName());
        newRole.setDepartment(departmentInDb);
    }
    Role savedRole = roleDao.saveRole(newRole);
    RoleResponse roleResponse = new RoleResponse(savedRole);
    LOGGER.info("Succeed to add role, role: {}, current_user: {}", roleResponse, HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&CREATE_ROLE_SUCCESSFULLY}", roleResponse);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RoleResponse(com.webank.wedatasphere.qualitis.response.RoleResponse) UserAndRoleResponse(com.webank.wedatasphere.qualitis.response.UserAndRoleResponse) Transactional(org.springframework.transaction.annotation.Transactional)

Example 87 with UnExpectedRequestException

use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.

the class ClusterInfoServiceImpl method deleteClusterInfo.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteClusterInfo(DeleteClusterInfoRequest request) throws UnExpectedRequestException {
    // 检查参数
    checkRequest(request);
    // 根据id查找ClusterInfo,不存在则抛出异常
    Long clusterInfoId = request.getClusterInfoId();
    ClusterInfo clusterInfoInDb = clusterInfoDao.findById(clusterInfoId);
    if (clusterInfoInDb == null) {
        throw new UnExpectedRequestException("id {&DOES_NOT_EXIST}");
    }
    // 删除clusterInfo
    clusterInfoDao.deleteClusterInfo(clusterInfoInDb);
    LOGGER.info("Succeed to delete cluster_info. id: {}", request.getClusterInfoId());
    return new GeneralResponse<>("200", "{&DELETE_CLUSTER_INFO_SUCCESSFULLY}", null);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 88 with UnExpectedRequestException

use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.

the class ClusterInfoServiceImpl method modifyClusterInfo.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> modifyClusterInfo(ModifyClusterInfoRequest request) throws UnExpectedRequestException {
    // 检查参数
    checkRequest(request);
    // 根据id查找clusterInfo,不存在抛出异常
    Long id = request.getClusterInfoId();
    ClusterInfo clusterInfoInDb = clusterInfoDao.findById(id);
    if (clusterInfoInDb == null) {
        throw new UnExpectedRequestException("id {&DOES_NOT_EXIST}");
    }
    LOGGER.info("Succeed to find cluster_info. cluster_info: {}", clusterInfoInDb);
    // 修改clusterInfo信息
    String clusterName = request.getClusterName();
    String clusterType = request.getClusterType();
    clusterInfoInDb.setClusterName(clusterName);
    clusterInfoInDb.setClusterType(clusterType);
    clusterInfoInDb.setLinkisAddress(request.getLinkisAddress());
    clusterInfoInDb.setLinkisToken(request.getLinkisToken());
    // 保存clusterInfo
    ClusterInfo savedClusterInfo = clusterInfoDao.saveClusterInfo(clusterInfoInDb);
    LOGGER.info("Succeed to modify cluster_info. cluster_info: {}", savedClusterInfo);
    return new GeneralResponse<>("200", "{&MODIFY_CLUSTER_INFO_SUCCESSFULLY}", null);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 89 with UnExpectedRequestException

use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.

the class SystemConfigServiceImpl method modifySystemConfig.

@Override
@Transactional(rollbackFor = Exception.class)
public GeneralResponse<?> modifySystemConfig(ModifySystemConfigRequest request) throws UnExpectedRequestException {
    // Check Argument
    ModifySystemConfigRequest.checkRequest(request);
    checkKeyName(request.getKeyName());
    // Find System Config by key name
    String keyName = request.getKeyName();
    String value = request.getValue();
    SystemConfig systemConfigInDb = systemConfigDao.findByKeyName(keyName);
    if (null == systemConfigInDb) {
        throw new UnExpectedRequestException("key name {&DOES_NOT_EXIST}");
    }
    LOGGER.info("{&SUCCEED_TO_FIND_SYSTEM_CONFIG}. key:{}, value: {}", systemConfigInDb.getKeyName(), systemConfigInDb.getValue());
    // 修改url并保存
    systemConfigInDb.setValue(value);
    SystemConfig savedSystemConfig = systemConfigDao.saveSystemConfig(systemConfigInDb);
    LOGGER.info("{&SUCCEED_TO_MODIFY_SYSTEM_CONFIG}. key: {}, value: {}", savedSystemConfig.getKeyName(), savedSystemConfig.getValue());
    return new GeneralResponse<>("200", "{&SUCCEED_TO_MODIFY_SYSTEM_CONFIG}", null);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) SystemConfig(com.webank.wedatasphere.qualitis.entity.SystemConfig) Transactional(org.springframework.transaction.annotation.Transactional)

Example 90 with UnExpectedRequestException

use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.

the class ProjectServiceImpl method getProjectDetail.

@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<ProjectDetailResponse> getProjectDetail(Long projectId, PageRequest pageRequest) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check existence of project
    Project projectInDb = projectDao.findById(projectId);
    if (projectInDb == null) {
        throw new UnExpectedRequestException("Project id {&DOES_NOT_EXIST}");
    }
    String username = HttpUtils.getUserName(httpServletRequest);
    // Check if user has permission get project.
    List<Integer> permissions = new ArrayList<>();
    permissions.add(ProjectUserPermissionEnum.BUSSMAN.getCode());
    checkProjectPermission(projectInDb, username, permissions);
    // Find rules by project
    List<Rule> rules = ruleDao.findByProjectWithPage(projectInDb, pageRequest.getPage(), pageRequest.getSize());
    int total = ruleDao.countByProject(projectInDb);
    ProjectDetailResponse projectDetailResponse = new ProjectDetailResponse(projectInDb, rules);
    projectDetailResponse.setTotal(total);
    LOGGER.info("Succeed to get get project detail. project_id: {}, response: {}", projectId, projectDetailResponse);
    return new GeneralResponse<>("200", "{&GET_PROJECT_DETAIL_SUCCESSFULLY}", projectDetailResponse);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Project(com.webank.wedatasphere.qualitis.project.entity.Project) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ProjectDetailResponse(com.webank.wedatasphere.qualitis.project.response.ProjectDetailResponse) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)150 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)97 ArrayList (java.util.ArrayList)56 Transactional (org.springframework.transaction.annotation.Transactional)54 Project (com.webank.wedatasphere.qualitis.project.entity.Project)33 User (com.webank.wedatasphere.qualitis.entity.User)32 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)32 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)25 Map (java.util.Map)24 ClusterInfo (com.webank.wedatasphere.qualitis.entity.ClusterInfo)22 List (java.util.List)22 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)19 IOException (java.io.IOException)19 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)17 Date (java.util.Date)17 HashMap (java.util.HashMap)17 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)15 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)15 Collectors (java.util.stream.Collectors)15 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)14