Package io.wcm.caravan.hal.comparison
Interface HalComparisonStrategy
-
@ConsumerType public interface HalComparisonStrategy
A user-defined configuration strategy for theHalComparison
service that can be implemented dynamically and context-aware.With the default implementations in this interface, the comparison will run as long as the crawler finds more links that haven't been processed yet, and will compare all embedded relations. Depending on your data structures, it is essential to restrict crawling to specific relations by implementing the
ignoreLinkTo(HalComparisonContext)
method.
-
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default Function<io.wcm.caravan.hal.resource.HalResource,String>
getIdProvider(HalComparisonContext context)
Can be implemented by the service consumer to improve the detection of additional, removed and re-ordered embedded resources.default List<Map<String,Object>>
getVariablesToExpandLinkTemplate(HalComparisonContext context, io.wcm.caravan.hal.resource.Link expectedLink, io.wcm.caravan.hal.resource.Link actualLink)
Can be implemented by the service consumer to expand specific link templates, so that the expanded link is then crawled and included in the comparison.default boolean
ignoreEmbeddedAt(HalComparisonContext halContext)
Can be implemented by the service consumer to exclude specific embedded resources from comparison.default boolean
ignoreLinkTo(HalComparisonContext halContext)
Can be implemented by the service consumer to exclude specific links from crawling and comparison.
-
-
-
Method Detail
-
ignoreEmbeddedAt
default boolean ignoreEmbeddedAt(HalComparisonContext halContext)
Can be implemented by the service consumer to exclude specific embedded resources from comparison.- Parameters:
halContext
- the relational location of the embedded resource to be compared- Returns:
- true if that resource (and everything below) should not be compared
-
ignoreLinkTo
default boolean ignoreLinkTo(HalComparisonContext halContext)
Can be implemented by the service consumer to exclude specific links from crawling and comparison.- Parameters:
halContext
- the relational location of a linked resource to be followed- Returns:
- true if that resource (and everything below) should not be followed & compared
-
getVariablesToExpandLinkTemplate
default List<Map<String,Object>> getVariablesToExpandLinkTemplate(HalComparisonContext context, io.wcm.caravan.hal.resource.Link expectedLink, io.wcm.caravan.hal.resource.Link actualLink)
Can be implemented by the service consumer to expand specific link templates, so that the expanded link is then crawled and included in the comparison. By default, link templates are not expanded and won't be crawled (only the template variables will be compared).- Parameters:
context
- the relational location of a link templateexpectedLink
- the full link template as found in the expected resource treeactualLink
- the full link template as found in the actual resource tree- Returns:
- a list that contains one map of variables for each expanded instance of this link template that should be created
-
getIdProvider
default Function<io.wcm.caravan.hal.resource.HalResource,String> getIdProvider(HalComparisonContext context)
Can be implemented by the service consumer to improve the detection of additional, removed and re-ordered embedded resources. By default, the "title" property of the embedded resources is used to find matching pairs. If your resources have some property that is unique in the context (and unlikely to change between environments), you should return a function that extracts that property's value.- Parameters:
context
- the relational location of an embedded resource- Returns:
- a function to extract an id that can be used to determine whether a specific resource was added/removed/reordered. If null is returned, the matching algorithm will use the title property
-
-