use of com.webank.wedatasphere.qualitis.rule.response.RuleNodeResponses in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method exportRuleByGroupId.
@Override
public GeneralResponse<RuleNodeResponses> exportRuleByGroupId(Long ruleGroupId) throws UnExpectedRequestException {
// Check existence of ruleGroup
RuleGroup ruleGroup = ruleGroupDao.findById(ruleGroupId);
if (ruleGroup == null) {
throw new UnExpectedRequestException("Rule group [Id = " + ruleGroupId + "] does not exist.");
}
LOGGER.info("Succeed to find rule group. Rule group id: {}.", ruleGroup.getId());
List<RuleNodeResponse> responses = new ArrayList<>();
try {
List<Rule> rules = ruleDao.findByRuleGroup(ruleGroup);
if (CollectionUtils.isEmpty(rules)) {
throw new UnExpectedRequestException("Rule group [id = " + ruleGroup.getId() + "] does not have rules.");
}
for (Rule rule : rules) {
responses.add(ruleNodeResponse(rule));
}
} catch (IOException e) {
LOGGER.error("Failed to export rule because of JSON serialization opeartions.", e);
return new GeneralResponse<>("500", "{&FAILED_TO_EXPORT_RULE}", null);
}
LOGGER.info("Succeed to export rule. Rule info: {}", Arrays.toString(responses.toArray()));
RuleNodeResponses ruleNodeResponses = new RuleNodeResponses(responses);
return new GeneralResponse<>("200", "{&EXPORT_RULE_SUCCESSFULLY}", ruleNodeResponses);
}
Aggregations