Search in sources :

Example 6 with UnExpectedRequestException

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);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Project(com.webank.wedatasphere.qualitis.project.entity.Project) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) User(com.webank.wedatasphere.qualitis.entity.User) ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with UnExpectedRequestException

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;
}
Also used : Role(com.webank.wedatasphere.qualitis.entity.Role) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) Project(com.webank.wedatasphere.qualitis.project.entity.Project) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) User(com.webank.wedatasphere.qualitis.entity.User) ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser)

Example 8 with UnExpectedRequestException

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);
    }
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) TemplateRegexpExpr(com.webank.wedatasphere.qualitis.rule.entity.TemplateRegexpExpr)

Example 9 with UnExpectedRequestException

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);
}
Also used : DataSourceColumnRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceColumnRequest) DataSourceRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList)

Example 10 with UnExpectedRequestException

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;
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList)

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