private void writeConstraints(Collection<Constraint> constraints, JqassistantRules rules) { for (Constraint constraint : constraints) { ConstraintType constraintType = new ConstraintType(); constraintType.setId(constraint.getId()); constraintType.setDescription(constraint.getDescription()); constraintType.setSeverity(getSeverity(constraint.getSeverity(), ruleConfiguration.getDefaultConstraintSeverity())); writeExecutable(constraintType, constraint); writeRequiredConcepts(constraint, constraintType); rules.getConceptOrConstraintOrGroup().add(constraintType); } }
public static ConstraintBuilder builder() { return new ConstraintBuilder(new Constraint()); } }
/** * Prints all valid rules. * * @param visitor * The visitor. */ private void printValidRules(CollectRulesVisitor visitor) { logger.info("Groups [" + visitor.getGroups().size() + "]"); for (Group group : visitor.getGroups()) { logger.info(LOG_LINE_PREFIX + group.getId() + "\""); } logger.info("Constraints [" + visitor.getConstraints().size() + "]"); for (Constraint constraint : visitor.getConstraints().keySet()) { logger.info(LOG_LINE_PREFIX + constraint.getId() + "\" - " + constraint.getDescription()); } logger.info("Concepts [" + visitor.getConcepts().size() + "]"); for (Concept concept : visitor.getConcepts().keySet()) { logger.info(LOG_LINE_PREFIX + concept.getId() + "\" - " + concept.getDescription()); } }
@Override public void visitConstraint(Constraint constraint, Severity effectiveSeverity) throws RuleException { analyzerContext.getLogger() .info("Validating constraint '" + constraint.getId() + "' with severity: '" + constraint.getSeverity().getInfo(effectiveSeverity) + "'."); try { analyzerContext.getStore().beginTransaction(); reportPlugin.beginConstraint(constraint); reportPlugin.setResult(execute(constraint, effectiveSeverity)); reportPlugin.endConstraint(); analyzerContext.getStore().commitTransaction(); } catch (XOException e) { analyzerContext.getStore().rollbackTransaction(); throw new RuleException("Cannot validate constraint " + constraint.getId(), e); } }
this.processConceptOrConstraint(constraintSpec, context, constraint -> context.getBuilder().addConstraint(constraint), Constraint.builder());
for (Constraint constraint : ruleSet.getConstraintBucket().getAll()) { JSONObject constraintObject = new JSONObject(); constraintObject.put(JSON_OBJECT_KEY_ID, constraint.getId()); constraintObject.put(JSON_OBJECT_KEY_DESCRIPTION, constraint.getDescription()); constraintObject.put(JSON_OBJECT_KEY_CYPHER, getCypher(constraint)); constraints.put(constraintObject);
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); } } }
private Constraint createConstraint(String id, RuleSource ruleSource, ConstraintType referenceableType) throws RuleException { Executable<?> executable = createExecutable(referenceableType); String description = referenceableType.getDescription(); Map<String, Parameter> parameters = getRequiredParameters(referenceableType.getRequiresParameter()); SeverityEnumType severityType = referenceableType.getSeverity(); Severity severity = getSeverity(severityType, getRuleConfiguration().getDefaultConstraintSeverity()); List<ReferenceType> requiresConcept = referenceableType.getRequiresConcept(); Map<String, Boolean> requiresConcepts = getRequiresConcepts(requiresConcept); String deprecated = referenceableType.getDeprecated(); Verification verification = getVerification(referenceableType.getVerify()); Report report = getReport(referenceableType.getReport()); return Constraint.builder().id(id).description(description).ruleSource(ruleSource).severity(severity).deprecation(deprecated).executable(executable) .parameters(parameters).requiresConcepts(requiresConcepts).verification(verification).report(report).build(); }