kwin commented on code in PR #6:
URL: 
https://github.com/apache/sling-org-apache-sling-serviceuser-webconsole/pull/6#discussion_r2479019362


##########
src/main/java/org/apache/sling/serviceuser/webconsole/impl/ServiceUserWebConsolePlugin.java:
##########
@@ -295,18 +298,44 @@ private Bundle findBundle(String symbolicName, 
Map<String, Bundle> bundles) {
         return bundles.get(symbolicName);
     }
 
+    /**
+     * Helper to check if the specified node type has been registered
+     *
+     * @param resolver the resolver to check
+     * @param typeName the node type name to check
+     * @return true if the node type exists, false otherwise
+     */
+    private boolean hasRegisteredNodeType(@NotNull ResourceResolver resolver, 
@NotNull String typeName) {
+        boolean hasNodeType = false;
+        final @Nullable Session jcrSession = resolver.adaptTo(Session.class);
+        if (jcrSession != null) {
+            try {
+                final NodeTypeManager nodeTypeManager =
+                        jcrSession.getWorkspace().getNodeTypeManager();
+                hasNodeType = nodeTypeManager.hasNodeType(typeName);
+            } catch (RepositoryException e) {
+                log.warn("Unable to detemine if node type is registered", e);
+            }
+        }
+        return hasNodeType;
+    }
+
     private Object findConfigurations(ResourceResolver resolver, String name, 
List<String> affectedPaths) {
         List<String> configurations = new ArrayList<>();
 
-        Iterator<Resource> configResources = resolver.findResources(
-                "SELECT * FROM [sling:OsgiConfig] AS s WHERE 
(ISDESCENDANTNODE([/apps]) OR ISDESCENDANTNODE([/libs])) AND NAME(s) LIKE 
'org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended%' AND 
[user.mapping] LIKE '%="
-                        + name + "'",
-                Query.JCR_SQL2);
-        while (configResources.hasNext()) {
-            Resource configResource = configResources.next();
-            affectedPaths.add(configResource.getPath());
-            configurations.add(configResource.getPath());
+        Iterator<Resource> configResources;
+        if (hasRegisteredNodeType(resolver, "sling:OsgiConfig")) {
+            configResources = resolver.findResources(
+                    "SELECT * FROM [sling:OsgiConfig] AS s WHERE 
(ISDESCENDANTNODE([/apps]) OR ISDESCENDANTNODE([/libs])) AND NAME(s) LIKE 
'org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended%' AND 
[user.mapping] LIKE '%="

Review Comment:
   Not directly but if this is only about configs provided via OSGI installer 
there is 
https://sling.apache.org/apidocs/sling13/org/apache/sling/installer/api/info/InfoProvider.html



-- 
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]

Reply via email to