for (Map<String, Object> conceptSpec : concepts) { this.processConceptOrConstraint(conceptSpec, context, concept -> context.getBuilder().addConcept(concept), Concept.builder());
/** * Converts a list of {@link JqassistantRules} to a rule set. * * @param rules * The {@link JqassistantRules}. * @throws RuleException * If rules are not consistent. */ private void convert(List<JqassistantRules> rules, RuleSource ruleSource, RuleSetBuilder builder) throws RuleException { for (JqassistantRules rule : rules) { List<SeverityRuleType> severityRuleTypes = rule.getConceptOrConstraintOrGroup(); for (SeverityRuleType severityRuleType : severityRuleTypes) { String id = severityRuleType.getId(); if (severityRuleType instanceof ConceptType) { Concept concept = createConcept(id, ruleSource, (ConceptType) severityRuleType); builder.addConcept(concept); } else if (severityRuleType instanceof ConstraintType) { Constraint constraint = createConstraint(id, ruleSource, (ConstraintType) severityRuleType); builder.addConstraint(constraint); } else if (severityRuleType instanceof GroupType) { Group group = createGroup(id, ruleSource, (GroupType) severityRuleType); builder.addGroup(group); } } } }
private void extractExecutableRule(RuleSource ruleSource, AbstractBlock executableRuleBlock, RuleSetBuilder builder) throws RuleException { Attributes attributes = new Attributes(executableRuleBlock.getAttributes()); String id = executableRuleBlock.id(); if (id == null) { throw new RuleException("An id attribute is required for the rule '" + executableRuleBlock + "' (i.e. '[[rule:id]]' is required."); } String description = attributes.getString(TITLE, ""); if (description == null) { LOGGER.info("Description of rule is missing: Using empty text for description (source='{}', id='{}').", ruleSource.getId(), id); } Map<String, Boolean> required = getRequiresConcepts(ruleSource, id, attributes); Map<String, Parameter> parameters = getParameters(attributes.getString(REQUIRES_PARAMETERS)); Executable<?> executable = getExecutable(executableRuleBlock, attributes); if (executable != null) { Verification verification = getVerification(attributes); Report report = getReport(executableRuleBlock); if (CONCEPT.equals(executableRuleBlock.getRole())) { Severity severity = getSeverity(attributes, getRuleConfiguration().getDefaultConceptSeverity()); Concept concept = Concept.builder().id(id).description(description).severity(severity).executable(executable).requiresConcepts(required) .parameters(parameters).verification(verification).report(report).ruleSource(ruleSource).build(); builder.addConcept(concept); } else if (CONSTRAINT.equals(executableRuleBlock.getRole())) { Severity severity = getSeverity(attributes, getRuleConfiguration().getDefaultConstraintSeverity()); Constraint constraint = Constraint.builder().id(id).description(description).severity(severity).executable(executable) .requiresConcepts(required).parameters(parameters).verification(verification).report(report).ruleSource(ruleSource).build(); builder.addConstraint(constraint); } } }