use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.
the class ProjectServiceImpl method deleteProject.
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteProject(DeleteProjectRequest request) throws UnExpectedRequestException, PermissionDeniedRequestException {
// Check Arguments
DeleteProjectRequest.checkRequest(request);
// Check existence of project
Project projectInDb = projectDao.findById(request.getProjectId());
if (projectInDb == null) {
throw new UnExpectedRequestException("project_id {&DOES_NOT_EXIST}");
}
Long userId = HttpUtils.getUserId(httpServletRequest);
User user = null;
if (userId == null) {
user = userDao.findByUsername(request.getUsername());
if (user == null) {
throw new UnExpectedRequestException(String.format("{&FAILED_TO_FIND_USER} %s", request.getUsername()));
}
} else {
user = userDao.findById(userId);
}
// Check project permission
List<Integer> permissions = new ArrayList<>();
permissions.add(ProjectUserPermissionEnum.CREATOR.getCode());
checkProjectPermission(projectInDb, user.getUserName(), permissions);
List<Rule> rules = ruleDao.findByProject(projectInDb);
deleteAllRules(rules);
// Delete project
projectDao.deleteProject(projectInDb);
LOGGER.info("Succeed to delete project. project_id: {}", request.getProjectId());
return new GeneralResponse<>("200", "{&DELETE_PROJECT_SUCCESSFULLY}", null);
}
use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.
the class ProjectServiceImpl method addProjectReal.
@Override
public Project addProjectReal(Long userId, String projectName, String cnName, String projectDescription) throws UnExpectedRequestException {
User user = userDao.findById(userId);
// Automatically grant the highest authority to the system administrator.
Role role = roleDao.findByRoleName(ADMIN);
List<User> admins = userRoleDao.findByRole(role).stream().map(UserRole::getUser).collect(Collectors.toList());
// Check existence of project by project name.
Project projectInDb = projectDao.findByNameAndCreateUser(projectName, user.getUserName());
if (projectInDb != null) {
throw new UnExpectedRequestException(String.format("{&PROJECT}:%s {&ALREADY_EXIST}", projectName));
}
// Save project.
Project newProject = new Project(projectName, cnName, projectDescription, user.getUserName(), user.getChineseName(), user.getDepartment() != null ? user.getDepartment().getName() : "", ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date()));
// Create project user.
if (admins.contains(user)) {
createProjectUser(newProject, user);
} else {
createProjectUser(newProject, user);
for (User currentAdmin : admins) {
createProjectUser(newProject, currentAdmin);
}
}
return newProject;
}
use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.
the class AutoArgumentAdapter method getRegexpValue.
/**
* If replaceByRequest = true, return value in request
* Else return value in database
* @param templateMidTableInputMeta
* @param templateArgumentRequests
* @return
*/
private Map<String, String> getRegexpValue(TemplateMidTableInputMeta templateMidTableInputMeta, List<TemplateArgumentRequest> templateArgumentRequests) throws UnExpectedRequestException {
if (templateMidTableInputMeta.getReplaceByRequest()) {
// Get value in request
String regexp = findRequestById(templateMidTableInputMeta.getId(), templateArgumentRequests).getArgumentValue();
String value = escapeExprSpecialWord(regexp);
return ImmutableMap.of("value", value);
} else {
String key = null;
// Get value in database
if (templateMidTableInputMeta.getRegexpType().equals(TemplateRegexpTypeEnum.DATE.getCode())) {
key = findRequestById(templateMidTableInputMeta.getId(), templateArgumentRequests).getArgumentValue();
}
TemplateRegexpExpr templateRegexpExpr = regexpExprMapperRepository.findByRegexpTypeAndKeyName(templateMidTableInputMeta.getRegexpType(), key);
if (templateRegexpExpr == null) {
throw new UnExpectedRequestException("KeyName: [" + key + "] is not supported");
}
String value = escapeExprSpecialWord(templateRegexpExpr.getRegexpValue());
Map<String, String> map = new HashMap<>(2);
map.put("value", value);
map.put("originValue", key);
return Collections.unmodifiableMap(map);
}
}
use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.
the class AddFileRuleRequestBuilder method solveDatasource.
private void solveDatasource(String datasource) throws UnExpectedRequestException {
List<DataSourceColumnRequest> dataSourceColumnRequests = new ArrayList<>();
DataSourceRequest dataSourceRequest = new DataSourceRequest();
String clusterName;
String database;
String table;
String filter;
String[] datasourceStrs = datasource.split(SpecCharEnum.COLON.getValue());
if (datasourceStrs.length > TWO) {
throw new UnExpectedRequestException("Datasource param is illegle");
}
String[] datasources = datasourceStrs[0].split(SpecCharEnum.PERIOD.getValue());
filter = datasourceStrs.length >= TWO ? datasourceStrs[1] : "";
if (datasources.length != FOUR && datasources.length != THREE) {
throw new UnExpectedRequestException("Datasource param is illegle");
}
clusterName = datasources[0];
database = datasources[1];
table = datasources[2];
dataSourceRequest.setClusterName(clusterName);
dataSourceRequest.setDbName(database);
dataSourceRequest.setTableName(table);
dataSourceRequest.setColNames(dataSourceColumnRequests);
dataSourceRequest.setFilter(filter);
dataSourceRequest.setProxyUser(userName);
this.addFileRuleRequest.setDatasource(dataSourceRequest);
}
use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.
the class AddMultiRuleRequestBuilder method addRuleMetric.
@Override
public AddRequestBuilder addRuleMetric(String ruleMetricName) throws UnExpectedRequestException {
RuleMetric ruleMetricInDb = ruleMetricDao.findByName(ruleMetricName);
if (ruleMetricInDb != null) {
setRuleMetricEnCode(ruleMetricInDb.getEnCode());
return this;
}
String[] infos = ruleMetricName.split(SpecCharEnum.BOTTOM_BAR.getValue());
if (infos.length != FOUR) {
throw new UnExpectedRequestException("The metric name does not meet specifications");
}
String en = infos[2];
List<String> ruleMetricNames = new ArrayList<>(1);
ruleMetricNames.add(ruleMetricName);
addMultiSourceRuleRequest.setRuleMetricNamesForBdpClient(ruleMetricNames);
setRuleMetricEnCode(en);
return this;
}
Aggregations