use of com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType in project Qualitis by WeBankFinTech.
the class RuleTemplateServiceImpl method getModifyRuleTemplateDetail.
@Override
public RuleTemplateResponse getModifyRuleTemplateDetail(Long templateId) throws UnExpectedRequestException {
// Check template existence
Template templateInDb = checkRuleTemplate(templateId);
RuleTemplateResponse response = new RuleTemplateResponse(templateInDb);
response.setClusterNum(templateInDb.getClusterNum());
response.setDbNum(templateInDb.getDbNum());
response.setTableNum(templateInDb.getTableNum());
response.setFieldNum(templateInDb.getFieldNum());
List<TemplateDataSourceType> templateDataSourceTypes = templateDataSourceTypeDao.findByTemplate(templateInDb);
response.setDatasourceType(templateDataSourceTypes.stream().map(TemplateDataSourceType::getDataSourceTypeId).collect(Collectors.toList()));
response.setActionType(templateInDb.getActionType());
response.setMidTableAction(templateInDb.getMidTableAction());
response.setSaveMidTable(templateInDb.getSaveMidTable());
List<TemplateOutputMetaResponse> outputMetaResponses = new ArrayList<>(1);
List<TemplateMidTableInputMetaResponse> midTableInputMetaResponses = new ArrayList<>(2);
List<TemplateStatisticsInputMetaResponse> statisticsInputMetaResponses = new ArrayList<>(1);
for (TemplateOutputMeta templateOutputMeta : templateInDb.getTemplateOutputMetas()) {
TemplateOutputMetaResponse templateOutputMetaResponse = new TemplateOutputMetaResponse();
templateOutputMetaResponse.setOutputName(templateOutputMeta.getOutputName());
outputMetaResponses.add(templateOutputMetaResponse);
}
response.setTemplateOutputMetaResponses(outputMetaResponses);
for (TemplateMidTableInputMeta templateMidTableInputMeta : templateInDb.getTemplateMidTableInputMetas()) {
TemplateMidTableInputMetaResponse templateMidTableInputMetaResponse = new TemplateMidTableInputMetaResponse();
templateMidTableInputMetaResponse.setName(templateMidTableInputMeta.getName());
templateMidTableInputMetaResponse.setPlaceholder(templateMidTableInputMeta.getPlaceholder());
templateMidTableInputMetaResponse.setPlaceholderDescription(templateMidTableInputMeta.getPlaceholderDescription());
templateMidTableInputMetaResponse.setInputType(templateMidTableInputMeta.getInputType());
midTableInputMetaResponses.add(templateMidTableInputMetaResponse);
}
response.setTemplateMidTableInputMetaResponses(midTableInputMetaResponses);
for (TemplateStatisticsInputMeta templateStatisticsInputMeta : templateInDb.getStatisticAction()) {
TemplateStatisticsInputMetaResponse templateStatisticsInputMetaResponse = new TemplateStatisticsInputMetaResponse();
templateStatisticsInputMetaResponse.setName(templateStatisticsInputMeta.getName());
templateStatisticsInputMetaResponse.setFuncName(templateStatisticsInputMeta.getFuncName());
templateStatisticsInputMetaResponse.setValue(templateStatisticsInputMeta.getValue());
templateStatisticsInputMetaResponse.setValueType(templateStatisticsInputMeta.getValueType());
statisticsInputMetaResponses.add(templateStatisticsInputMetaResponse);
}
response.setTemplateStatisticsInputMetaResponses(statisticsInputMetaResponses);
return response;
}
use of com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType in project Qualitis by WeBankFinTech.
the class RuleTemplateServiceImpl method deleteRuleTemplate.
@Override
public void deleteRuleTemplate(Long templateId) throws UnExpectedRequestException, PermissionDeniedRequestException {
// Check template existence
Template templateInDb = checkRuleTemplate(templateId);
// Check operator permission
User userInDb = userDao.findById(HttpUtils.getUserId(httpServletRequest));
List<UserRole> userRoles = userRoleDao.findByUser(userInDb);
Integer roleType = roleService.getRoleType(userRoles);
if (roleType.equals(RoleDefaultTypeEnum.PROJECTOR.getCode())) {
LOGGER.info("The projector is going to delete template.");
if (templateInDb.getLevel().intValue() != RuleTemplateLevelEnum.PERSONAL_TEMPLATE.getCode()) {
throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
}
if (userInDb.getId() != (templateInDb.getCreateUser().getId())) {
throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
}
} else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
LOGGER.info("The department admin is going to delete template.");
if (templateInDb.getLevel().intValue() == RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode()) {
throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
}
List<User> createUsers = new ArrayList<>();
for (UserRole userRole : userRoles) {
Department department = userRole.getRole().getDepartment();
if (department != null) {
List<User> userList = userDao.findByDepartment(department);
createUsers.addAll(userList);
}
}
boolean exist = false;
for (User user : createUsers) {
if (user.getId() == templateInDb.getCreateUser().getId()) {
exist = true;
break;
}
}
if (!exist) {
throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
}
} else {
if (templateInDb.getLevel().equals(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode())) {
if (templateInDb.getCreateUser() == null || !userInDb.getUserName().equals(templateInDb.getCreateUser().getUserName())) {
throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
}
}
LOGGER.info("The system admin is going to delete template.");
}
// Check rules of template
ruleService.checkRuleOfTemplate(templateInDb);
// Delete 'Templatedepartment' or 'TemplateUser'
clearTemplateUser(templateInDb);
List<TemplateDataSourceType> templateDataSourceTypes = templateDataSourceTypeDao.findByTemplate(templateInDb);
for (TemplateDataSourceType templateDataSourceType : templateDataSourceTypes) {
templateDataSourceTypeDao.delete(templateDataSourceType);
}
ruleTemplateDao.deleteTemplate(templateInDb);
}
use of com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType in project Qualitis by WeBankFinTech.
the class RuleTemplateServiceImpl method deleteFileRuleTemplate.
@Override
public void deleteFileRuleTemplate(Long templateId) throws UnExpectedRequestException {
// Check template existence
Template templateInDb = checkRuleTemplate(templateId);
ruleTemplateDao.deleteTemplate(templateInDb);
List<TemplateDataSourceType> templateDataSourceTypes = templateDataSourceTypeDao.findByTemplate(templateInDb);
for (TemplateDataSourceType templateDataSourceType : templateDataSourceTypes) {
templateDataSourceTypeDao.delete(templateDataSourceType);
}
}
use of com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method importRuleReal.
private void importRuleReal(RuleNodeRequest ruleNodeRequest, Rule ruleInDb, Rule rule, Project projectInDb, Template template, RuleGroup ruleGroup, Set<AlarmConfig> alarmConfigs, Set<RuleVariable> ruleVariables, Set<RuleDataSource> ruleDataSources, Set<RuleDataSourceMapping> ruleDataSourceMappings) throws IOException, UnExpectedRequestException {
if (ruleInDb == null) {
LOGGER.info("Import in first time. That means adding.");
rule.setProject(projectInDb);
ruleGroup.setProjectId(projectInDb.getId());
if (RuleTypeEnum.CUSTOM_RULE.getCode().equals(rule.getRuleType())) {
Template saveTemplate = ruleTemplateDao.saveTemplate(template);
Set<Integer> templateDateTypes = ruleDataSources.stream().filter(currRuleDataSource -> currRuleDataSource.getDatasourceType() != null).map(RuleDataSource::getDatasourceType).collect(Collectors.toSet());
for (Integer templateDataType : templateDateTypes) {
TemplateDataSourceType templateDataSourceType = new TemplateDataSourceType(templateDataType, saveTemplate);
templateDataSourceTypeDao.save(templateDataSourceType);
}
Set<TemplateStatisticsInputMeta> templateStatisticsInputMetas = new HashSet<>();
Set<TemplateOutputMeta> templateOutputMetaSet = new HashSet<>();
if (rule.getOutputName() != null && rule.getFunctionType() != null && rule.getFunctionContent() != null) {
templateStatisticsInputMetas = templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(rule.getOutputName(), rule.getFunctionType(), rule.getFunctionContent(), saveTemplate.getSaveMidTable(), saveTemplate);
templateOutputMetaSet = templateOutputMetaService.getAndSaveTemplateOutputMeta(rule.getOutputName(), rule.getFunctionType(), saveTemplate.getSaveMidTable(), saveTemplate);
} else {
List<RuleMetric> ruleMetrics = alarmConfigs.stream().map(AlarmConfig::getRuleMetric).collect(Collectors.toList());
for (RuleMetric ruleMetric : ruleMetrics) {
templateStatisticsInputMetas.addAll(templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(ruleMetric.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), ruleMetric.getName(), saveTemplate.getSaveMidTable(), saveTemplate));
templateOutputMetaSet.addAll(templateOutputMetaService.getAndSaveTemplateOutputMeta(ruleMetric.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), saveTemplate.getSaveMidTable(), saveTemplate));
}
}
saveTemplate.setStatisticAction(templateStatisticsInputMetas);
saveTemplate.setTemplateOutputMetas(templateOutputMetaSet);
rule.setTemplate(saveTemplate);
} else if (RuleTypeEnum.FILE_TEMPLATE_RULE.getCode().equals(rule.getRuleType())) {
LOGGER.info("Start to import file rule. {}", rule.getName());
// Save file rule template.
rule.setTemplate(ruleTemplateDao.saveTemplate(template));
// Save file rule group
rule.setRuleGroup(ruleGroup);
Rule savedRule = ruleDao.saveRule(rule);
// Save file alarmconfig
List<AlarmConfig> alarmConfigList = new ArrayList<>();
for (AlarmConfig alarmConfig : alarmConfigs) {
ruleMetricSycn(alarmConfig);
alarmConfig.setRule(savedRule);
alarmConfigList.add(alarmConfig);
}
List<RuleDataSource> ruleDataSourceList = new ArrayList<>();
for (RuleDataSource ruleDataSource : ruleDataSources) {
ruleDataSource.setProjectId(projectInDb.getId());
ruleDataSource.setRule(savedRule);
ruleDataSourceList.add(ruleDataSource);
}
savedRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(alarmConfigList)));
savedRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
LOGGER.info("Finish to import file rule. {}", rule.getName());
return;
} else {
// When trying out the newly created rule template in the development center, the production center needs to synchronize the rule template.
synchroRuleTemplate(ruleNodeRequest, rule, template, ruleDataSources);
}
rule.setRuleGroup(ruleGroup);
Rule savedRule = ruleDao.saveRule(rule);
saveRuleInfo(savedRule, template, projectInDb, alarmConfigs, ruleVariables, ruleDataSources, ruleDataSourceMappings);
if (ruleNodeRequest.getChildRuleObject() != null) {
importChildRule(savedRule, ruleGroup, ruleNodeRequest, projectInDb);
}
} else {
LOGGER.info("Import multiple times. That is to update.");
if (RuleTypeEnum.FILE_TEMPLATE_RULE.getCode().equals(rule.getRuleType())) {
LOGGER.info("Start to update import file rule. {}", rule.getName());
Set<AlarmConfig> alarmConfigList = new HashSet<>();
for (AlarmConfig alarmConfig : alarmConfigs) {
ruleMetricSycn(alarmConfig);
alarmConfig.setRule(ruleInDb);
alarmConfigList.add(alarmConfig);
}
updateImportedFileRule(rule, ruleInDb, ruleGroup, alarmConfigList, ruleDataSources);
LOGGER.info("Finish to update import file rule. {}", rule.getName());
return;
}
updateImportedRule(rule, ruleInDb, ruleGroup, ruleNodeRequest, template, alarmConfigs, ruleVariables, ruleDataSources, ruleDataSourceMappings);
}
}
use of com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method synchroRuleTemplate.
public void synchroRuleTemplate(RuleNodeRequest ruleNodeRequest, Rule rule, Template template, Set<RuleDataSource> ruleDataSources) throws IOException {
Template templateInDb = ruleTemplateDao.findById(template.getId());
Template templateNameInDb = null;
if (StringUtils.isNotBlank(template.getImportExportName())) {
templateNameInDb = ruleTemplateDao.findByImportExportName(template.getImportExportName());
}
if (templateInDb == null && templateNameInDb == null) {
LOGGER.info("Start to synchronize the rule template. Template: {}", template);
ObjectMapper objectMapper = new ObjectMapper();
// Template meta info.
Set<TemplateOutputMeta> templateOutputMetaSet = objectMapper.readValue(ruleNodeRequest.getTemplateTemplateOutputMetaObject(), new TypeReference<Set<TemplateOutputMeta>>() {
});
Set<TemplateMidTableInputMeta> templateMidTableInputMetaSet = objectMapper.readValue(ruleNodeRequest.getTemplateTemplateMidTableInputMetaObject(), new TypeReference<Set<TemplateMidTableInputMeta>>() {
});
Set<TemplateStatisticsInputMeta> templateStatisticsInputMetaSet = objectMapper.readValue(ruleNodeRequest.getTemplateTemplateStatisticsInputMetaObject(), new TypeReference<Set<TemplateStatisticsInputMeta>>() {
});
Template savedTemplate = ruleTemplateDao.saveTemplate(template);
Set<TemplateOutputMeta> templateOutputMetas = new HashSet<>();
for (TemplateOutputMeta outputMeta : templateOutputMetaSet) {
outputMeta.setTemplate(savedTemplate);
templateOutputMetas.add(templateOutputMetaDao.saveTemplateOutputMeta(outputMeta));
}
savedTemplate.setTemplateOutputMetas(templateOutputMetas);
LOGGER.info("Success to save template output meta. TemplateOutputMetas: {}", savedTemplate.getTemplateOutputMetas());
List<TemplateMidTableInputMeta> templateMidTableInputMetas = new ArrayList<>();
for (TemplateMidTableInputMeta templateMidTableInputMeta : templateMidTableInputMetaSet) {
templateMidTableInputMeta.setTemplate(savedTemplate);
templateMidTableInputMetas.add(templateMidTableInputMeta);
}
templateMidTableInputMetas.sort(Comparator.comparing(TemplateMidTableInputMeta::getId));
savedTemplate.setTemplateMidTableInputMetas(templateMidTableInputMetaService.saveAll(templateMidTableInputMetas));
LOGGER.info("Success to save template mid_table input meta. TemplateMidTableInputMetas: {}", savedTemplate.getTemplateMidTableInputMetas());
List<TemplateStatisticsInputMeta> templateStatisticsInputMetas = new ArrayList<>();
for (TemplateStatisticsInputMeta templateStatisticsInputMeta : templateStatisticsInputMetaSet) {
templateStatisticsInputMeta.setTemplate(savedTemplate);
templateStatisticsInputMetas.add(templateStatisticsInputMeta);
}
savedTemplate.setStatisticAction(templateStatisticsInputMetaService.saveAll(templateStatisticsInputMetas));
LOGGER.info("Success to save template statistics input meta. templateStatisticsInputMetas: {}", savedTemplate.getStatisticAction());
Set<Integer> templateDateTypes = ruleDataSources.stream().filter(currRuleDataSource -> currRuleDataSource.getDatasourceType() != null).map(RuleDataSource::getDatasourceType).collect(Collectors.toSet());
for (Integer templateDataType : templateDateTypes) {
TemplateDataSourceType templateDataSourceType = new TemplateDataSourceType(templateDataType, savedTemplate);
templateDataSourceTypeDao.save(templateDataSourceType);
}
LOGGER.info("Success to save template data types. Template data types: {}", Arrays.toString(templateDateTypes.toArray()));
LOGGER.info("Finished to synchronize the rule template. Template: {}", savedTemplate);
rule.setTemplate(savedTemplate);
} else if (templateInDb != null) {
rule.setTemplate(templateInDb);
} else if (templateNameInDb != null) {
rule.setTemplate(templateNameInDb);
} else {
rule.setTemplate(template);
}
}
Aggregations