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


##########
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:
   @kwin With the 
[e5a97f1](https://github.com/apache/sling-org-apache-sling-serviceuser-webconsole/pull/6/commits/e5a97f1880a1dc4f89a72b7ce19a15d870cc10f7)
 checkin, I made a new attempt to utilize OSGi Config Admin API for 
reading/writing.  I left the old way as a fallback since I didn't see a 
convenient way to tell ConfiguationAdmin to store the data in a specific 
location.
   
   A summary of the changed behavior is below:
   
   1. Use ConfigurationAdmin to find the OSGi configurations to display on the 
service user details UI
     a) Also change the rendering of the configuration items to render a link 
to the /system/console/configMgr/[pid] for each item
   
   2. Add a code path for using ConfigurationAdmin to store the configuration 
state from the "Create Service User" form.
     a) Changed the "Application Path" field to now be optional.  Also this 
field now not rendered at all if the "sling:OsgiConfig" nodetype has not been 
deployed since it doesn't make sense without JcrInstaller available.
     b) Added a new "Configuration Instance Identifier" field which defines the 
suffix for the configuration PID.  Previously this value came from the last 
segment of the "Application Path" field which is now optional.
   
   So the new behavior is that if "Application Path" is empty or the 
"sling:OsgiConfig" nodetype is not available, the configuration will be applied 
by delegating to the ConfigurationAdmin APIs.  Otherwise, when there is a 
specific "Application Path" value supplied, the configuration will be applied 
by persisting a configuration resource as it was before.
   
   Please let me know if this resolves your previous concerns.



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