Class AbstractConstraintValidationHandler

java.lang.Object
dev.metaschema.core.model.constraint.AbstractConstraintValidationHandler
All Implemented Interfaces:
IConstraintValidationHandler
Direct Known Subclasses:
FindingCollectingConstraintValidationHandler, LoggingConstraintValidationHandler

public abstract class AbstractConstraintValidationHandler extends Object implements IConstraintValidationHandler
Provides messaging for constraint violations.
  • Constructor Details

    • AbstractConstraintValidationHandler

      public AbstractConstraintValidationHandler()
  • Method Details

    • getPathFormatter

      @NonNull public IPathFormatter getPathFormatter()
      Get the formatter used to generate content paths for validation issue locations.
      Returns:
      the formatter
    • setPathFormatter

      public void setPathFormatter(@NonNull IPathFormatter formatter)
      Set the path formatter to use when generating contextual paths in validation messages.
      Parameters:
      formatter - the path formatter to use
    • toPath

      protected String toPath(@NonNull INodeItem item)
      Get the path of the provided item using the configured path formatter.
      Parameters:
      item - the node item to generate the path for
      Returns:
      the path
      See Also:
    • newCardinalityMinimumViolationMessage

      @NonNull protected String newCardinalityMinimumViolationMessage(@NonNull ICardinalityConstraint constraint, @NonNull INodeItem target, @NonNull ISequence<? extends INodeItem> testedItems, @NonNull DynamicContext dynamicContext) throws ConstraintValidationException
      Construct a new violation message for the provided constraint applied to the node.
      Parameters:
      constraint - the constraint the requested message pertains to
      target - the item the constraint targeted
      testedItems - the items tested by the constraint
      dynamicContext - the Metapath dynamic execution context to use for Metapath evaluation
      Returns:
      the new message
      Throws:
      ConstraintValidationException - if the custom message contains a Metapath expression that is invalid or if the expression failed to evaluate
    • newCardinalityMaximumViolationMessage

      @NonNull protected String newCardinalityMaximumViolationMessage(@NonNull ICardinalityConstraint constraint, @NonNull INodeItem target, @NonNull ISequence<? extends INodeItem> testedItems, @NonNull DynamicContext dynamicContext) throws ConstraintValidationException
      Construct a new violation message for the provided constraint applied to the node.
      Parameters:
      constraint - the constraint the requested message pertains to
      target - the item the constraint targeted
      testedItems - the items tested by the constraint
      dynamicContext - the Metapath dynamic execution context to use for Metapath evaluation
      Returns:
      the new message
      Throws:
      ConstraintValidationException - if the custom message contains a Metapath expression that is invalid or if the expression failed to evaluate
    • newIndexDuplicateKeyViolationMessage

      @NonNull protected String newIndexDuplicateKeyViolationMessage(@NonNull IIndexConstraint constraint, @NonNull INodeItem node, @NonNull INodeItem oldItem, @NonNull INodeItem target, @NonNull DynamicContext dynamicContext) throws ConstraintValidationException
      Construct a new violation message for the provided constraint applied to the node.
      Parameters:
      constraint - the constraint the requested message pertains to
      node - the item the constraint targeted
      oldItem - the original item matching the constraint
      target - the new item matching the constraint
      dynamicContext - the Metapath dynamic execution context to use for Metapath evaluation
      Returns:
      the new message
      Throws:
      ConstraintValidationException - if the custom message contains a Metapath expression that is invalid or if the expression failed to evaluate
    • newUniqueKeyViolationMessage

      @NonNull protected String newUniqueKeyViolationMessage(@NonNull IUniqueConstraint constraint, @NonNull INodeItem node, @NonNull INodeItem oldItem, @NonNull INodeItem target, @NonNull DynamicContext dynamicContext) throws ConstraintValidationException
      Construct a new violation message for the provided constraint applied to the node.
      Parameters:
      constraint - the constraint the requested message pertains to
      node - the item the constraint targeted
      oldItem - the original item matching the constraint
      target - the new item matching the constraint
      dynamicContext - the Metapath dynamic execution context to use for Metapath evaluation
      Returns:
      the new message
      Throws:
      ConstraintValidationException - if the custom message contains a Metapath expression that is invalid or if the expression failed to evaluate
    • newMatchPatternViolationMessage

      @NonNull protected String newMatchPatternViolationMessage(@NonNull IMatchesConstraint constraint, @NonNull INodeItem node, @NonNull INodeItem target, @NonNull String value, @NonNull Pattern pattern, @NonNull DynamicContext dynamicContext) throws ConstraintValidationException
      Construct a new violation message for the provided constraint applied to the node.
      Parameters:
      constraint - the constraint the requested message pertains to
      node - the item the constraint targeted
      target - the target matching the constraint
      value - the target's value
      pattern - the expected pattern
      dynamicContext - the Metapath dynamic execution context to use for Metapath evaluation
      Returns:
      the new message
      Throws:
      ConstraintValidationException - if the custom message contains a Metapath expression that is invalid or if the expression failed to evaluate
    • newMatchDatatypeViolationMessage

      @NonNull protected String newMatchDatatypeViolationMessage(@NonNull IMatchesConstraint constraint, @NonNull INodeItem node, @NonNull INodeItem target, @NonNull String value, @NonNull IDataTypeAdapter<?> adapter, @NonNull DynamicContext dynamicContext) throws ConstraintValidationException
      Construct a new violation message for the provided constraint applied to the node.
      Parameters:
      constraint - the constraint the requested message pertains to
      node - the item the constraint targeted
      target - the target matching the constraint
      value - the target's value
      adapter - the expected data type adapter
      dynamicContext - the Metapath dynamic execution context to use for Metapath evaluation
      Returns:
      the new message
      Throws:
      ConstraintValidationException - if the custom message contains a Metapath expression that is invalid or if the expression failed to evaluate
    • newExpectViolationMessage

      @NonNull protected String newExpectViolationMessage(@NonNull IExpectConstraint constraint, @NonNull INodeItem node, @NonNull INodeItem target, @NonNull DynamicContext dynamicContext) throws ConstraintValidationException
      Construct a new violation message for the provided constraint applied to the node.
      Parameters:
      constraint - the constraint the requested message pertains to
      node - the item the constraint targeted
      target - the target matching the constraint
      dynamicContext - the Metapath dynamic execution context to use for Metapath evaluation
      Returns:
      the new message
      Throws:
      ConstraintValidationException - if the custom message contains a Metapath expression that is invalid or if the expression failed to evaluate
    • newReportViolationMessage

      @NonNull protected String newReportViolationMessage(@NonNull IReportConstraint constraint, @NonNull INodeItem node, @NonNull INodeItem target, @NonNull DynamicContext dynamicContext) throws ConstraintValidationException
      Construct a new message for the provided report constraint applied to the node.

      Report constraints generate findings when their test expression evaluates to true, which is the opposite of expect constraints.

      Parameters:
      constraint - the constraint the requested message pertains to
      node - the item the constraint targeted
      target - the target matching the constraint
      dynamicContext - the Metapath dynamic execution context to use for Metapath evaluation
      Returns:
      the new message
      Throws:
      ConstraintValidationException - if the custom message contains a Metapath expression that is invalid or if the expression failed to evaluate
    • newAllowedValuesViolationMessage

      @NonNull protected String newAllowedValuesViolationMessage(@NonNull List<IAllowedValuesConstraint> constraints, @NonNull INodeItem target)
      Construct a new violation message for the provided constraint applied to the node.
      Parameters:
      constraints - the constraints the requested message pertains to
      target - the target matching the constraint
      Returns:
      the new message
    • newIndexDuplicateViolationMessage

      @NonNull protected String newIndexDuplicateViolationMessage(@NonNull IIndexConstraint constraint, @NonNull INodeItem node)
      Construct a new violation message for the provided constraint applied to the node.
      Parameters:
      constraint - the constraint the requested message pertains to
      node - the item the constraint targeted
      Returns:
      the new message
    • newIndexMissMessage

      @NonNull protected String newIndexMissMessage(@NonNull IIndexHasKeyConstraint constraint, @NonNull INodeItem node, @NonNull INodeItem target, @NonNull List<String> key, @NonNull DynamicContext dynamicContext) throws ConstraintValidationException
      Construct a new violation message for the provided constraint applied to the node.
      Parameters:
      constraint - the constraint the requested message pertains to
      node - the item the constraint targeted
      target - the target matching the constraint
      key - the key derived from the target that failed to be found in the index
      dynamicContext - the Metapath dynamic execution context to use for Metapath evaluation
      Returns:
      the new message
      Throws:
      ConstraintValidationException - if the custom message contains a Metapath expression that is invalid or if the expression failed to evaluate
    • newMissingIndexViolationMessage

      @NonNull protected String newMissingIndexViolationMessage(@NonNull IIndexHasKeyConstraint constraint, @NonNull INodeItem node, @NonNull INodeItem target, @NonNull String message, @NonNull DynamicContext dynamicContext)
      Construct a new generic violation message for the provided constraint applied to the node.
      Parameters:
      constraint - the constraint the requested message pertains to
      node - the item the constraint targeted
      target - the target matching the constraint
      message - the message to be added before information about the target path
      dynamicContext - the Metapath dynamic execution context to use for Metapath evaluation
      Returns:
      the new message