joerghoh commented on code in PR #175:
URL:
https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/175#discussion_r2075981295
##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/AliasHandler.java:
##########
@@ -308,14 +311,52 @@ private boolean doUpdateAliasInMap(final Resource
resource) {
return changed;
} else {
log.warn("containingResource is null for alias on {}, skipping.",
resource.getPath());
+ return false;
}
-
- return false;
}
public @NotNull Map<String, Collection<String>> getAliasMap(final String
parentPath) {
- Map<String, Collection<String>> aliasMapForParent =
aliasMapsMap.get(parentPath);
- return aliasMapForParent != null ? aliasMapForParent :
Collections.emptyMap();
+ Map<String, Collection<String>> result = this.aliasMapsMap !=
UNITIALIZED_MAP
+ ? getAliasMapFromCache(parentPath)
+ : getAliasMapFromRepo(parentPath);
+ return result != null ? result : Collections.emptyMap();
+ }
+
+ private @Nullable Map<String, Collection<String>>
getAliasMapFromCache(final String parentPath) {
+ return aliasMapsMap.get(parentPath);
+ }
+
+ // TODO: there's an opportunity for optimization when the caller already
has a Resource
+ private @Nullable Map<String, Collection<String>>
getAliasMapFromRepo(final String parentPath) {
+
+ Map<String, Collection<String>> result = null;
+
+ try (final ResourceResolver resolver =
+
factory.getServiceResourceResolver(factory.getServiceUserAuthenticationInfo(SERVICE_USER)))
{
+
+ Resource parent = resolver.getResource(parentPath);
+ result = getAliasMapFromRepo(parent);
+ } catch (LoginException ex) {
+ log.error("Could not obtain resolver", ex);
+ }
+
+ return result;
+ }
+
+ private @Nullable Map<String, Collection<String>>
getAliasMapFromRepo(final Resource parent) {
Review Comment:
```suggestion
private @Nullable Map<String, Collection<String>>
getAliasMapFromRepo(@Nullable final Resource parent) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]