private void applyConcepts(RuleSet ruleSet, String conceptPattern, Severity parentSeverity, Severity requestedSeverity) throws RuleException { List<Concept> matchingConcepts = ruleSet.getConceptBucket().match(conceptPattern); if (matchingConcepts.isEmpty()) { LOGGER.warn("Could not find concepts matching to '{}'.", matchingConcepts); } else { for (Concept matchingConcept : matchingConcepts) { applyConcept(ruleSet, matchingConcept, getEffectiveSeverity(matchingConcept, parentSeverity, requestedSeverity)); } } }
private void validateConstraints(RuleSet ruleSet, String constraintPattern, Severity parentSeverity, Severity requestedSeverity) throws RuleException { List<Constraint> matchingConstraints = ruleSet.getConstraintBucket().match(constraintPattern); if (matchingConstraints.isEmpty()) { LOGGER.warn("Could not find constraints matching to '{}'.", constraintPattern); } else { for (Constraint matchingConstraint : matchingConstraints) { validateConstraint(ruleSet, matchingConstraint, getEffectiveSeverity(matchingConstraint, parentSeverity, requestedSeverity)); } } }
private void executeGroups(RuleSet ruleSet, String groupPattern, Severity parentSeverity, Severity requestedSeverity) throws RuleException { List<Group> matchingGroups = ruleSet.getGroupsBucket().match(groupPattern); if (matchingGroups.isEmpty()) { LOGGER.warn("Could not find groups matching to '{}'.", groupPattern); } else { for (Group matchingGroup : matchingGroups) { executeGroup(ruleSet, matchingGroup, getEffectiveSeverity(matchingGroup, parentSeverity, requestedSeverity)); } } }
/** * Logs the given rule set on level info. * * @param ruleSet * The rule set. */ public void printRuleSet(RuleSet ruleSet) throws RuleException { RuleSelection ruleSelection = RuleSelection.builder() .conceptIds(ruleSet.getConceptBucket().getIds()) .constraintIds(ruleSet.getConstraintBucket().getIds()) .groupIds(ruleSet.getGroupsBucket().getIds()).build(); printRuleSet(ruleSet, ruleSelection); }
/** * Reads the available metric groups. * * @return the map of metric groups */ private MetricGroupsBucket readMetricGroups() { return getAvailableRules().getMetricGroupsBucket(); }
@Override public void write(RuleSet ruleSet, Writer writer) throws com.buschmais.jqassistant.core.analysis.api.rule.RuleException { CollectRulesVisitor visitor = new CollectRulesVisitor(); RuleSelection ruleSelection = RuleSelection.builder().groupIds(ruleSet.getGroupsBucket().getIds()) .constraintIds(ruleSet.getConstraintBucket().getIds()).conceptIds(ruleSet.getConceptBucket().getIds()).build(); new RuleSetExecutor(visitor, configuration).execute(ruleSet, ruleSelection); JqassistantRules rules = new JqassistantRules(); writeGroups(visitor.getGroups(), rules); writeConcepts(visitor.getConcepts().keySet(), rules); writeConstraints(visitor.getConstraints().keySet(), rules); marshal(writer, rules); }
for (Concept concept : ruleSet.getConceptBucket().getAll()) { JSONObject conceptObject = new JSONObject(); conceptObject.put(JSON_OBJECT_KEY_ID, concept.getId()); for (Constraint constraint : ruleSet.getConstraintBucket().getAll()) { JSONObject constraintObject = new JSONObject(); constraintObject.put(JSON_OBJECT_KEY_ID, constraint.getId()); for (Group group : ruleSet.getGroupsBucket().getAll()) { JSONObject groupObject = new JSONObject(); groupObject.put(JSON_OBJECT_KEY_ID, group.getId());
public static RuleSelection select(RuleSet ruleSet, List<String> groupIds, List<String> constraintIds, List<String> conceptIds) { if (groupIds.isEmpty() && conceptIds.isEmpty() && constraintIds.isEmpty() && ruleSet.getGroupsBucket().getIds().contains(GROUP_DEFAULT)) { return builder().groupId(GROUP_DEFAULT).build(); } return builder().groupIds(new LinkedHashSet<>(groupIds)).constraintIds(new LinkedHashSet<>(constraintIds)).conceptIds(new LinkedHashSet<>(conceptIds)).build(); } }
private boolean applyRequiredConcepts(RuleSet ruleSet, ExecutableRule<?> rule) throws RuleException { boolean requiredConceptsApplied = true; for (Map.Entry<String, Boolean> entry : rule.getRequiresConcepts().entrySet()) { List<Concept> requiredConcepts = ruleSet.getConceptBucket().match(entry.getKey()); for (Concept requiredConcept : requiredConcepts) { boolean conceptResult = applyConcept(ruleSet, requiredConcept, requiredConcept.getSeverity()); Boolean optional = entry.getValue(); if (optional == null) { optional = configuration.isRequiredConceptsAreOptionalByDefault(); } requiredConceptsApplied = requiredConceptsApplied && (conceptResult || optional); } } return requiredConceptsApplied; }