// Evaluates the specified Criteria on the specified flowfile. Clones the // specified flow file for each rule that is applied. private boolean evaluateCriteria( final ProcessSession session, final ProcessContext context, final Criteria criteria, final FlowFile flowfile, final Map<FlowFile, List<Rule>> matchedRules) { final ComponentLog logger = getLogger(); final List<Rule> rules = criteria.getRules(); // consider each rule and hold a copy of the flowfile for each matched rule for (final Rule rule : rules) { // evaluate the rule if (evaluateRule(context, rule, flowfile)) { final FlowFile flowfileToUse; // determine if we should use the original flow file or clone if (FlowFilePolicy.USE_ORIGINAL.equals(criteria.getFlowFilePolicy()) || matchedRules.isEmpty()) { flowfileToUse = flowfile; } else { // clone the original for this rule flowfileToUse = session.clone(flowfile); } // store the flow file to use when executing this rule List<Rule> rulesForFlowFile = matchedRules.get(flowfileToUse); if (rulesForFlowFile == null) { rulesForFlowFile = new ArrayList<>(); matchedRules.put(flowfileToUse, rulesForFlowFile); } rulesForFlowFile.add(rule); // log if appropriate if (logger.isDebugEnabled()) { logger.debug( this + " all conditions met for rule '" + rule.getName() + "'. Using flow file - " + flowfileToUse); } } } return !matchedRules.isEmpty(); }
@Override public Collection<SearchResult> search(final SearchContext context) { final String term = context.getSearchTerm(); final Collection<SearchResult> results = new ArrayList<>(); if (StringUtils.isBlank(context.getAnnotationData())) { return results; } try { // parse the annotation data final Criteria criteria = CriteriaSerDe.deserialize(context.getAnnotationData()); // ensure there are some rules if (criteria.getRules() != null) { final FlowFilePolicy flowFilePolicy = criteria.getFlowFilePolicy(); if (flowFilePolicy != null && StringUtils.containsIgnoreCase(flowFilePolicy.name(), term)) { results.add( new SearchResult.Builder() .label("FlowFile policy") .match(flowFilePolicy.name()) .build()); } for (final Rule rule : criteria.getRules()) { if (StringUtils.containsIgnoreCase(rule.getName(), term)) { results.add( new SearchResult.Builder().label("Rule name").match(rule.getName()).build()); } // ensure there are some conditions if (rule.getConditions() != null) { for (final Condition condition : rule.getConditions()) { if (StringUtils.containsIgnoreCase(condition.getExpression(), term)) { results.add( new SearchResult.Builder() .label(String.format("Condition in rule '%s'", rule.getName())) .match(condition.getExpression()) .build()); } } } // ensure there are some actions if (rule.getActions() != null) { for (final Action action : rule.getActions()) { if (StringUtils.containsIgnoreCase(action.getAttribute(), term)) { results.add( new SearchResult.Builder() .label(String.format("Action in rule '%s'", rule.getName())) .match(action.getAttribute()) .build()); } if (StringUtils.containsIgnoreCase(action.getValue(), term)) { results.add( new SearchResult.Builder() .label(String.format("Action in rule '%s'", rule.getName())) .match(action.getValue()) .build()); } } } } } return results; } catch (Exception e) { return results; } }