Search in sources :

Example 11 with Project

use of com.webank.wedatasphere.qualitis.project.entity.Project in project Qualitis by WeBankFinTech.

the class ProjectUserServiceImpl method getAllProjectUser.

@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<List<ProjectUserResponse>> getAllProjectUser(Long projectId) throws UnExpectedRequestException, PermissionDeniedRequestException {
    List<ProjectUserResponse> projectUserResponses = new ArrayList<>();
    Project projectInDb = projectDao.findById(projectId);
    if (projectInDb == null) {
        throw new UnExpectedRequestException("{&PROJECT}: [ID=" + projectId + "] {&DOES_NOT_EXIST}");
    }
    String userName = HttpUtils.getUserName(httpRequest);
    List<ProjectUser> projectUsers = projectUserDao.findByProject(projectInDb);
    List<String> projectUserNames = projectUsers.stream().map(ProjectUser::getUserName).collect(Collectors.toList());
    if (!projectUserNames.contains(userName)) {
        throw new PermissionDeniedRequestException("{&HAS_NO_PERMISSION_TO_ACCESS}", 403);
    }
    for (ProjectUser currentProjectUser : projectUsers) {
        List<String> userNames = projectUserResponses.stream().map(ProjectUserResponse::getAuthorizedUser).collect(Collectors.toList());
        String currentUser = currentProjectUser.getUserName();
        if (userNames.contains(currentUser)) {
            continue;
        }
        String projectCreator = projectInDb.getCreateUser();
        ProjectUserResponse projectUserResponse = new ProjectUserResponse(projectInDb.getName(), projectCreator, currentUser);
        List<Integer> permissions = getPermissionList(projectUsers, currentUser);
        projectUserResponse.setPermissions(permissions);
        projectUserResponses.add(projectUserResponse);
    }
    return new GeneralResponse<>("200", "{&SUCCESS_TO_GET_PROJECT_USER}", projectUserResponses);
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) ArrayList(java.util.ArrayList) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Project(com.webank.wedatasphere.qualitis.project.entity.Project) ProjectUserResponse(com.webank.wedatasphere.qualitis.project.response.ProjectUserResponse) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with Project

use of com.webank.wedatasphere.qualitis.project.entity.Project in project Qualitis by WeBankFinTech.

the class RuleNodeServiceImpl method importRuleGroup.

@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<RuleResponse> importRuleGroup(RuleNodeRequests ruleNodeRequests) throws UnExpectedRequestException, IOException, PermissionDeniedRequestException {
    // Project, rule group.
    Project projectInDb = projectDao.findById(ruleNodeRequests.getNewProjectId());
    ObjectMapper objectMapper = new ObjectMapper();
    RuleGroup ruleGroup = objectMapper.readValue(ruleNodeRequests.getRuleNodeRequests().iterator().next().getRuleGroupObject(), RuleGroup.class);
    RuleGroup ruleGroupInDb = ruleGroupDao.saveRuleGroup(new RuleGroup(ruleGroup.getRuleGroupName(), projectInDb.getId()));
    if (DEV_CENTER.equals(localConfig.getCenter())) {
        CopyRuleRequest copyRuleRequest = new CopyRuleRequest();
        copyRuleRequest.setSourceRuleGroupId(ruleGroup.getId());
        copyRuleRequest.setCreateUser(projectInDb.getCreateUser());
        copyRuleRequest.setTargetRuleGroupId(ruleGroupInDb.getId());
        copyRuleRequest.setTargetProjectId(ruleNodeRequests.getNewProjectId());
        copyRuleByRuleGroupId(copyRuleRequest);
        return new GeneralResponse<>("200", "{&IMPORT_RULE_SUCCESSFULLY}", new RuleResponse(ruleGroupInDb.getId()));
    }
    if (projectInDb != null) {
        LOGGER.info("Project info : {}", projectInDb.toString());
    } else {
        // For special case:
        // A project already exists in DSS. when creating a workflow in this project and publish it, Qualitis service cannot find the project.
        // Because Qualitis did not run when this project had been created in DSS.
        LOGGER.info("Start to create workflow project. Project[id = {}] is not exist.", ruleNodeRequests.getNewProjectId());
        String userName = ruleNodeRequests.getUserName();
        User currentUser = userDao.findByUsername(userName);
        if (currentUser == null) {
            LOGGER.info("Start to create user. User name is {}", userName);
            try {
                userService.autoAddUser(userName);
                currentUser = userDao.findByUsername(userName);
            } catch (RoleNotFoundException e) {
                LOGGER.error("Role cannot be found. Exception: {}", e);
            }
        }
        Project newProject = projectService.addProjectReal(currentUser.getId(), currentUser.getUserName() + "_project_" + UUID.randomUUID().toString(), currentUser.getUserName() + "_项目_" + UUID.randomUUID().toString(), "Auto created.");
        newProject.setProjectType(ProjectTypeEnum.WORKFLOW_PROJECT.getCode());
        projectInDb = projectDao.saveProject(newProject);
        LOGGER.info("Succeed to create project. New project: {}", projectInDb.toString());
    }
    for (RuleNodeRequest request : ruleNodeRequests.getRuleNodeRequests()) {
        importRule(request, projectInDb, ruleGroupInDb, objectMapper);
    }
    return new GeneralResponse<>("200", "{&IMPORT_RULE_SUCCESSFULLY}", new RuleResponse(ruleGroupInDb.getId()));
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Project(com.webank.wedatasphere.qualitis.project.entity.Project) ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) ExcelTemplateFileRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject) User(com.webank.wedatasphere.qualitis.entity.User) RuleNodeRequest(com.webank.wedatasphere.qualitis.rule.request.RuleNodeRequest) RuleResponse(com.webank.wedatasphere.qualitis.rule.response.RuleResponse) RoleNotFoundException(javax.management.relation.RoleNotFoundException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) CopyRuleRequest(com.webank.wedatasphere.qualitis.rule.request.CopyRuleRequest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with Project

use of com.webank.wedatasphere.qualitis.project.entity.Project in project Qualitis by WeBankFinTech.

the class RuleServiceImpl method modifyRuleDetailReal.

private GeneralResponse<RuleResponse> modifyRuleDetailReal(ModifyRuleRequest request, String loginUser) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check Arguments
    ModifyRuleRequest.checkRequest(request);
    // Check existence of rule
    Rule ruleInDb = ruleDao.findById(request.getRuleId());
    if (ruleInDb == null) {
        throw new UnExpectedRequestException("rule_id [" + request.getRuleId() + "] {&DOES_NOT_EXIST}");
    }
    // Check existence of project
    Project projectInDb = projectService.checkProjectExistence(ruleInDb.getProject().getId(), loginUser);
    if (!ruleInDb.getRuleType().equals(RuleTypeEnum.SINGLE_TEMPLATE_RULE.getCode())) {
        throw new UnExpectedRequestException("rule(id: [" + request.getRuleId() + "]) {&IS_NOT_A_RULE_WITH_TEMPLATE}");
    }
    // Check permissions of project
    List<Integer> permissions = new ArrayList<>();
    permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
    projectService.checkProjectPermission(projectInDb, loginUser, permissions);
    LOGGER.info("Succeed to find rule. rule_id: {}", ruleInDb.getId());
    // For workflow node context.
    String csId = request.getCsId();
    boolean cs = false;
    if (StringUtils.isNotBlank(csId)) {
        cs = true;
    }
    ruleInDb.setCsId(csId);
    // Check existence of rule template
    Template templateInDb = ruleTemplateService.checkRuleTemplate(request.getRuleTemplateId());
    // Check datasource size
    checkDataSourceNumber(templateInDb, request.getDatasource());
    // Check cluster name supported
    checkDataSourceClusterLimit(request.getDatasource());
    // Check arguments size
    checkRuleArgumentSize(request.getTemplateArgumentRequests(), templateInDb);
    // Check existence of rule
    checkRuleName(request.getRuleName(), ruleInDb.getProject(), ruleInDb.getId());
    // Basic rule info.
    setBasicInfo(ruleInDb, templateInDb, request, loginUser);
    // Delete all alarm_config,rule_variable,rule_datasource
    alarmConfigService.deleteByRule(ruleInDb);
    LOGGER.info("Succeed to delete all alarm_config. rule_id: {}", ruleInDb.getId());
    ruleVariableService.deleteByRule(ruleInDb);
    LOGGER.info("Succeed to delete all rule_variable. rule_id: {}", ruleInDb.getId());
    ruleDataSourceService.deleteByRule(ruleInDb);
    LOGGER.info("Succeed to delete all rule_dataSources. rule_id: {}", ruleInDb.getId());
    // Update rule count of datasource
    ruleDataSourceService.updateRuleDataSourceCount(ruleInDb, -1);
    Rule savedRule = ruleDao.saveRule(ruleInDb);
    LOGGER.info("Succeed to save rule. rule_id: {}", savedRule.getId());
    // For repeat fps table name when concurrent task is running.
    addUuid(request.getDatasource());
    // Save alarm_config,ruleVariable和ruleDataSource
    List<RuleVariable> ruleVariables = autoAdaptArgumentAndGetRuleVariable(templateInDb, request.getDatasource(), request.getTemplateArgumentRequests(), savedRule);
    List<RuleVariable> savedRuleVariables = ruleVariableService.saveRuleVariable(ruleVariables);
    LOGGER.info("Succeed to save rule_variable, rule_variable: {}", savedRuleVariables);
    List<AlarmConfig> savedAlarmConfigs = new ArrayList<>();
    if (request.getAlarm()) {
        savedAlarmConfigs = alarmConfigService.checkAndSaveAlarmVariable(request.getAlarmVariable(), savedRule);
        LOGGER.info("Succeed to save alarm_configs, alarm_configs: {}", savedAlarmConfigs);
    }
    List<RuleDataSource> savedRuleDataSource = ruleDataSourceService.checkAndSaveRuleDataSource(request.getDatasource(), savedRule, cs, loginUser);
    LOGGER.info("Succeed to save rule_dataSources, rule_dataSources: {}", savedRuleDataSource);
    savedRule.setRuleVariables(new HashSet<>(savedRuleVariables));
    savedRule.setAlarmConfigs(new HashSet<>(savedAlarmConfigs));
    savedRule.setRuleDataSources(new HashSet<>(savedRuleDataSource));
    // Update rule count of datasource
    ruleDataSourceService.updateRuleDataSourceCount(ruleInDb, 1);
    RuleResponse response = new RuleResponse(savedRule);
    LOGGER.info("Succeed to modify rule. response: {}", response);
    // projectEventService.record(request.getProjectId(), loginUser, "modify", "rule[name= " + savedRule.getName() + "].", EventTypeEnum.MODIFY_PROJECT.getCode());
    return new GeneralResponse<>("200", "{&MODIFY_RULE_SUCCESSFULLY}", response);
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RuleResponse(com.webank.wedatasphere.qualitis.rule.response.RuleResponse) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Project(com.webank.wedatasphere.qualitis.project.entity.Project)

Example 14 with Project

use of com.webank.wedatasphere.qualitis.project.entity.Project in project Qualitis by WeBankFinTech.

the class ProjectEventServiceImpl method record.

@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public void record(Long projectId, String userName, String operation, String content, Integer typeId) {
    Project projectInDb = projectDao.findById(projectId);
    ProjectEvent projectEvent = new ProjectEvent(projectInDb, userName, operation + " " + content, ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date()), typeId);
    try {
        projectEventDao.save(projectEvent);
    } catch (Exception e) {
        LOGGER.error("Failed to record project event.");
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : Project(com.webank.wedatasphere.qualitis.project.entity.Project) Date(java.util.Date) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ProjectEvent(com.webank.wedatasphere.qualitis.project.entity.ProjectEvent) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with Project

use of com.webank.wedatasphere.qualitis.project.entity.Project in project Qualitis by WeBankFinTech.

the class ProjectServiceImpl method getProjectEvents.

@Override
public GeneralResponse<GetAllResponse<ProjectEventResponse>> getProjectEvents(Long projectId, Integer typeId, PageRequest pageRequest) throws UnExpectedRequestException, PermissionDeniedRequestException {
    PageRequest.checkRequest(pageRequest);
    String loginUser = HttpUtils.getUserName(httpServletRequest);
    // Check project existence.
    Project projectInDb = checkProjectExistence(projectId, loginUser);
    List<Integer> permissions = new ArrayList<>();
    permissions.add(ProjectUserPermissionEnum.BUSSMAN.getCode());
    checkProjectPermission(projectInDb, loginUser, permissions);
    List<ProjectEvent> projectEvents = projectEventDao.find(pageRequest.getPage(), pageRequest.getSize(), projectInDb, typeId);
    long total = projectEventDao.count(projectInDb, typeId);
    List<ProjectEventResponse> projectEventResponses = new ArrayList<>(projectEvents.size());
    for (ProjectEvent projectEvent : projectEvents) {
        ProjectEventResponse projectEventResponse = new ProjectEventResponse(projectEvent);
        projectEventResponses.add(projectEventResponse);
    }
    GetAllResponse<ProjectEventResponse> response = new GetAllResponse<>(total, projectEventResponses);
    return new GeneralResponse<>("200", "{&SUCCESS_TO_GET_PROJECT_EVENT}", response);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Project(com.webank.wedatasphere.qualitis.project.entity.Project) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) ProjectEventResponse(com.webank.wedatasphere.qualitis.project.response.ProjectEventResponse) ProjectEvent(com.webank.wedatasphere.qualitis.project.entity.ProjectEvent)

Aggregations

Project (com.webank.wedatasphere.qualitis.project.entity.Project)46 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)33 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)28 Transactional (org.springframework.transaction.annotation.Transactional)25 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)22 ArrayList (java.util.ArrayList)17 User (com.webank.wedatasphere.qualitis.entity.User)13 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)11 ExcelMultiTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject)11 Date (java.util.Date)11 ExcelCustomRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject)9 ExcelTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject)9 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)9 RuleResponse (com.webank.wedatasphere.qualitis.rule.response.RuleResponse)9 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)8 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)8 IOException (java.io.IOException)8 ClusterInfoNotConfigException (com.webank.wedatasphere.qualitis.exception.ClusterInfoNotConfigException)6 TaskNotExistException (com.webank.wedatasphere.qualitis.exception.TaskNotExistException)6 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)6