joerghoh commented on code in PR #20:
URL: 
https://github.com/apache/sling-org-apache-sling-discovery-oak/pull/20#discussion_r3703989639


##########
src/main/java/org/apache/sling/discovery/oak/OakDiscoveryService.java:
##########
@@ -515,53 +546,50 @@ private void doUpdateProperties() {
             resourceResolver.refresh();
 
             final ModifiableValueMap myInstanceMap = 
myInstance.adaptTo(ModifiableValueMap.class);
-            final Set<String> keys = new 
HashSet<String>(myInstanceMap.keySet());
-            for (final String key : keys) {
-                if (newProps.containsKey(key)) {
-                    // perfect
-                    continue;
-                } else if (key.indexOf(":") != -1) {
-                    // ignore
-                    continue;
-                } else {
-                    // remove
-                    myInstanceMap.remove(key);
-                }
-            }
-
-            boolean anyChanges = false;
-            for (final Entry<String, String> entry : newProps.entrySet()) {
-                Object existingValue = myInstanceMap.get(entry.getKey());
-                if (entry.getValue().equals(existingValue)) {
-                    // SLING-3389: dont rewrite the properties if nothing 
changed!
-                    if (logger.isDebugEnabled()) {
-                        logger.debug("doUpdateProperties: unchanged: {}={}", 
entry.getKey(), entry.getValue());
-                    }
-                    continue;
-                }
-                if (logger.isDebugEnabled()) {
-                    logger.debug("doUpdateProperties: changed: {}={}", 
entry.getKey(), entry.getValue());
-                }
-                anyChanges = true;
-                myInstanceMap.put(entry.getKey(), entry.getValue());
-            }
-
-            if (anyChanges) {
+            removeStaleKeys(myInstanceMap, newProps.keySet());
+            if (applyNewProperties(myInstanceMap, newProps)) {
                 resourceResolver.commit();
             }
         } catch (LoginException e) {
-            logger.error("handleEvent: could not log in administratively: " + 
e, e);
+            logger.error("doUpdateProperties: could not log in 
administratively: " + e, e);
             throw new RuntimeException("Could not log in to repository (" + e 
+ ")", e);
         } catch (PersistenceException e) {
-            logger.error("handleEvent: got a PersistenceException: " + e, e);
-            throw new RuntimeException( "Exception while talking to repository 
(" + e + ")", e);
+            logger.error("doUpdateProperties: got a PersistenceException: " + 
e, e);
+            throw new RuntimeException("Exception while talking to repository 
(" + e + ")", e);
         } finally {

Review Comment:
   NIT and while you are at it: can you use a try-with-resource approach here 
for more compact code?



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