Skip to content

Instantly share code, notes, and snippets.

@rah003
Forked from mkgl/VirtualUriMappingEval.groovy
Created November 11, 2019 14:06
Show Gist options
  • Save rah003/bb4098b531c071b77808f4519165c7ac to your computer and use it in GitHub Desktop.
Save rah003/bb4098b531c071b77808f4519165c7ac to your computer and use it in GitHub Desktop.
Show all Virtual URI mappings that matched a given URI and their associated weights
@Field private registry
import groovy.transform.Field
import info.magnolia.objectfactory.Components
import info.magnolia.virtualuri.VirtualUriRegistry
import static java.util.stream.Collectors.joining
registry = Components.getComponent(VirtualUriRegistry.class)
URI uri = new URI("/rssFeeds/karamba");
def allMatches = this.registry.allDefinitions.stream()
.map { it.mapUri(uri) }
.filter { it.present }
.map { it.get() }
.sorted { it.compareTo }
.map { "$it.toUri (weight $it.weight) [${referenceId(it.mapping)}]" }
.collect(joining("\n"))
private referenceId(mapping) {
registry.allProviders.stream()
.filter { it.valid && it.get() == mapping }
.map { it.metadata.referenceId }
.findAny()
.orElse("unknown")
}
print "URI mappings from $uri:\n$allMatches"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment