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()));
}
Aggregations