use of com.webank.wedatasphere.qualitis.response.GetAllResponse in project Qualitis by WeBankFinTech.
the class ProjectServiceImpl method getAllProjectByUserReal.
@Override
public GetAllResponse<ProjectResponse> getAllProjectByUserReal() {
// Get username
String loginUser = HttpUtils.getUserName(httpServletRequest);
// Find project user in different permissions.
List<Integer> permissions = new ArrayList<>();
permissions.add(ProjectUserPermissionEnum.CREATOR.getCode());
permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
permissions.add(ProjectUserPermissionEnum.OPERATOR.getCode());
permissions.add(ProjectUserPermissionEnum.BUSSMAN.getCode());
List<Project> projects = projectUserDao.findByUsernameAndPermission(loginUser, permissions);
long total = projectUserDao.countByUsernameAndPermission(loginUser, permissions);
List<ProjectResponse> projectResponses = new ArrayList<>();
for (Project project : projects) {
projectResponses.add(new ProjectResponse(project));
}
GetAllResponse<ProjectResponse> response = new GetAllResponse<>();
response.setTotal(total);
response.setData(projectResponses);
return response;
}
use of com.webank.wedatasphere.qualitis.response.GetAllResponse in project Qualitis by WeBankFinTech.
the class ProjectServiceImpl method getAllProjectByUserReal.
@Override
public GetAllResponse<ProjectResponse> getAllProjectByUserReal(PageRequest request, Integer projectType) throws UnExpectedRequestException {
// Check Arguments
PageRequest.checkRequest(request);
// Get user name
String userName = HttpUtils.getUserName(httpServletRequest);
// Paging get project
int page = request.getPage();
int size = request.getSize();
List<ProjectUser> projectUsers = projectUserDao.findByUsernameAndPermissionAndProjectType(userName, projectType, page, size);
long total = projectUserDao.countByUsernameAndPermissionAndProjectType(userName, projectType);
List<ProjectResponse> projectResponses = new ArrayList<>();
for (ProjectUser projectUser : projectUsers) {
projectResponses.add(new ProjectResponse(projectUser.getProject()));
}
GetAllResponse<ProjectResponse> response = new GetAllResponse<>();
response.setData(projectResponses);
response.setTotal(total);
return response;
}
use of com.webank.wedatasphere.qualitis.response.GetAllResponse in project Qualitis by WeBankFinTech.
the class RuleMetricServiceImpl method getAllRuleMetric.
@Override
public GeneralResponse<GetAllResponse<RuleMetricResponse>> getAllRuleMetric(PageRequest request) throws UnExpectedRequestException {
PageRequest.checkRequest(request);
String userName = HttpUtils.getUserName(httpServletRequest);
LOGGER.info("Start to get all rule metric, page request: [{}], user: [{}]", request.toString(), userName);
User loginUser = userDao.findByUsername(userName);
List<UserRole> userRoles = userRoleDao.findByUser(loginUser);
Integer roleType = roleService.getRoleType(userRoles);
List<RuleMetric> ruleMetrics = new ArrayList<>();
long total = 0;
if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
LOGGER.info("SYS_ADMIN will get all rule metrics.");
ruleMetrics.addAll(ruleMetricDao.findAllRuleMetrics(request.getPage(), request.getSize()));
total = ruleMetricDao.countAllRuleMetrics();
} else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
LOGGER.info("DEPARTMENT_ADMIN will get rule metrics of all management departments and all projectors.");
List<Department> departments = new ArrayList<>();
for (UserRole temp : userRoles) {
Department department = temp.getRole().getDepartment();
if (department != null) {
departments.add(department);
}
}
ruleMetrics.addAll(ruleMetricDao.findRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, null, request.getPage(), request.getSize()));
total = ruleMetricDao.countRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, null);
} else {
LOGGER.info("PROJECTOR will get rule metrics of department and own.");
List<Department> departments = new ArrayList<>();
departments.add(loginUser.getDepartment());
ruleMetrics.addAll(ruleMetricDao.findRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, loginUser, request.getPage(), request.getSize()));
total = ruleMetricDao.countRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, loginUser);
}
GetAllResponse<RuleMetricResponse> response = new GetAllResponse<>();
List<RuleMetricResponse> ruleMetricResponses = new ArrayList<>();
for (RuleMetric ruleMetric : ruleMetrics) {
ruleMetricResponses.add(new RuleMetricResponse(ruleMetric));
}
response.setData(ruleMetricResponses);
response.setTotal(total);
return new GeneralResponse<>("200", "{&GET_RULE_METRIC_SUCCESSFULLY}", response);
}
use of com.webank.wedatasphere.qualitis.response.GetAllResponse in project Qualitis by WeBankFinTech.
the class MetaDataServiceImpl method getUserTableByDbId.
@Override
public GeneralResponse<GetAllResponse<TableInfoDetail>> getUserTableByDbId(GetUserTableByDbIdRequest request) throws UnExpectedRequestException, MetaDataAcquireFailedException {
// Check Arguments
checkRequest(request);
// Get login user
String userName = HttpUtils.getUserName(httpServletRequest);
if (StringUtils.isNotBlank(request.getProxyUser())) {
userName = request.getProxyUser();
}
GetTableByUserAndDbRequest getTableByUserAndDbRequest = new GetTableByUserAndDbRequest(userName, request.getStartIndex(), request.getPageSize(), request.getClusterName(), request.getDbName());
DataInfo<TableInfoDetail> response = metaDataClient.getTableByUserAndDb(getTableByUserAndDbRequest);
GetAllResponse<TableInfoDetail> result = new GetAllResponse<>();
result.setTotal(response.getTotalCount());
result.setData(response.getContent());
LOGGER.info("Succeed to get table by database. database: {}.{}", request.getClusterName(), request.getDbName());
return new GeneralResponse<>("200", "{&GET_TABLE_SUCCESSFULLY}", result);
}
use of com.webank.wedatasphere.qualitis.response.GetAllResponse in project Qualitis by WeBankFinTech.
the class MetaDataController method getDbsByDataSource.
@GET
@Path("data_source/dbs")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public GeneralResponse<GetAllResponse<DbInfoDetail>> getDbsByDataSource(@QueryParam("clusterName") String clusterName, @QueryParam("proxyUser") String proxyUser, @QueryParam("dataSourceId") Long dataSourceId) {
try {
if (dataSourceId == null || StringUtils.isBlank(clusterName)) {
throw new UnExpectedRequestException("Request " + "{&CAN_NOT_BE_NULL_OR_EMPTY}");
}
Map response = metaDataService.getDbsByDataSource(clusterName, proxyUser, dataSourceId);
GetAllResponse allResponse = new GetAllResponse();
List<String> dbs = (List<String>) response.get("dbs");
List<DbInfoDetail> dbInfoDetails = new ArrayList<>(CollectionUtils.isEmpty(dbs) ? 0 : dbs.size());
for (String db : dbs) {
DbInfoDetail dbInfoDetail = new DbInfoDetail(db);
dbInfoDetails.add(dbInfoDetail);
}
allResponse.setTotal(CollectionUtils.isEmpty(dbInfoDetails) ? 0 : dbInfoDetails.size());
allResponse.setData(dbInfoDetails);
return new GeneralResponse<>("200", "{&GET_DB_SUCCESSFULLY}", allResponse);
} catch (MetaDataAcquireFailedException e) {
LOGGER.error(e.getMessage(), e);
return new GeneralResponse<>("500", e.getMessage(), null);
} catch (UnExpectedRequestException e) {
LOGGER.error(e.getMessage(), e);
return new GeneralResponse<>("500", e.getMessage(), null);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
return new GeneralResponse<>("500", "{&FAILED_TO_GET_DATABASE_BY_CLUSTER}", null);
}
}
Aggregations