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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations