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


##########
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:
   For me the whole approach is kind of wrong. Using OSGi Config Admin API for 
reading/writing that info should be used. Sling OSGi Installer with its 
`sling:OsgiConfig` nodes is just one of the multiple ways how to deploy an OSGi 
config…



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