Skip to content

Commit

Permalink
[grid] Improving matcher for the RelaySessionFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Sep 13, 2021
1 parent f2d458f commit 29c01fd
Showing 1 changed file with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,32 @@ public RelaySessionFactory(

@Override
public boolean test(Capabilities capabilities) {
return stereotype.getCapabilityNames().stream()
// If a request reaches this point is because the basic match of W3C caps has already been done.

// Custom matching in case a platformVersion is requested
boolean platformVersionMatch = capabilities.getCapabilityNames()
.stream()
.filter(name -> name.contains("platformVersion"))
.map(
name ->
Objects.equals(stereotype.getCapability(name), capabilities.getCapability(name)))
platformVersionCapName ->
Objects.equals(stereotype.getCapability(platformVersionCapName),
capabilities.getCapability(platformVersionCapName)))
.reduce(Boolean::logicalAnd)
.orElse(true);

return platformVersionMatch && stereotype.getCapabilityNames().stream()
.filter(name -> capabilities.asMap().containsKey(name))
.map(
name -> {
if (capabilities.getCapability(name) instanceof String) {
return stereotype.getCapability(name).toString()
.equalsIgnoreCase(capabilities.getCapability(name).toString());
} else {
return capabilities.getCapability(name) == null ||
Objects.equals(stereotype.getCapability(name), capabilities.getCapability(name));
}
}
)
.reduce(Boolean::logicalAnd)
.orElse(false);
}
Expand Down

0 comments on commit 29c01fd

Please sign in to comment.