Search in sources :

Example 1 with RuleNodeRequest

use of com.webank.wedatasphere.qualitis.rule.request.RuleNodeRequest 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)

Aggregations

User (com.webank.wedatasphere.qualitis.entity.User)1 Project (com.webank.wedatasphere.qualitis.project.entity.Project)1 ExcelMultiTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject)1 ExcelTemplateFileRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject)1 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)1 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)1 CopyRuleRequest (com.webank.wedatasphere.qualitis.rule.request.CopyRuleRequest)1 RuleNodeRequest (com.webank.wedatasphere.qualitis.rule.request.RuleNodeRequest)1 RuleResponse (com.webank.wedatasphere.qualitis.rule.response.RuleResponse)1 RoleNotFoundException (javax.management.relation.RoleNotFoundException)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 Transactional (org.springframework.transaction.annotation.Transactional)1