Search in sources :

Example 1 with RuleNodeResponses

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);
}
Also used : RuleNodeResponses(com.webank.wedatasphere.qualitis.rule.response.RuleNodeResponses) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RuleNodeResponse(com.webank.wedatasphere.qualitis.rule.response.RuleNodeResponse) ArrayList(java.util.ArrayList) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) IOException(java.io.IOException) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)

Aggregations

UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)1 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)1 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)1 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)1 RuleNodeResponse (com.webank.wedatasphere.qualitis.rule.response.RuleNodeResponse)1 RuleNodeResponses (com.webank.wedatasphere.qualitis.rule.response.RuleNodeResponses)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1