Skip to content

Instantly share code, notes, and snippets.

@mkgl
Last active January 31, 2020 10:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mkgl/c800a005b7ee960351fae1563d7a148f to your computer and use it in GitHub Desktop.
Save mkgl/c800a005b7ee960351fae1563d7a148f to your computer and use it in GitHub Desktop.
Show all Magnolia 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