kumaab commented on code in PR #545:
URL: https://github.com/apache/ranger/pull/545#discussion_r2006410941


##########
security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java:
##########
@@ -6741,33 +6741,53 @@ public void run() {
             getOrCreateLabel();
         }
 
+        private boolean doesPolicyExist(XXPolicy xPolicy) {
+            return daoMgr.getXXPolicy().getById(xPolicy.getId()) != null;
+        }
+
         private void getOrCreateLabel() {
             LOG.debug("==> AssociatePolicyLabel.getOrCreateLabel(policyId={}, 
label={})", xPolicy.getId(), policyLabel);
 
-            XXPolicyLabel xxPolicyLabel = 
daoMgr.getXXPolicyLabels().findByName(policyLabel);
-
-            if (xxPolicyLabel == null) {
-                xxPolicyLabel = 
daoMgr.getXXPolicyLabels().findByName(policyLabel);
+            if (doesPolicyExist(xPolicy)) {
+                LOG.debug("Searching for policyLabel: {}", policyLabel);
+                XXPolicyLabel xxPolicyLabel = 
daoMgr.getXXPolicyLabels().findByName(policyLabel);
+                LOG.debug("Search returned: {}", xxPolicyLabel);
 
                 if (xxPolicyLabel == null) {
-                    xxPolicyLabel = new XXPolicyLabel();
+                    LOG.debug("Searching again for policyLabel: {}", 
policyLabel);
+                    xxPolicyLabel = 
daoMgr.getXXPolicyLabels().findByName(policyLabel);
+                    LOG.debug("Another Search returned: {}", xxPolicyLabel);
 
-                    xxPolicyLabel.setPolicyLabel(policyLabel);
+                    if (xxPolicyLabel == null) {
+                        LOG.debug("Creating policyLabel: {}", policyLabel);
+                        xxPolicyLabel = new XXPolicyLabel();
 
-                    xxPolicyLabel = 
rangerAuditFields.populateAuditFieldsForCreate(xxPolicyLabel);
-                    xxPolicyLabel = 
daoMgr.getXXPolicyLabels().create(xxPolicyLabel);
+                        xxPolicyLabel.setPolicyLabel(policyLabel);
+
+                        xxPolicyLabel = 
rangerAuditFields.populateAuditFieldsForCreate(xxPolicyLabel);
+                        xxPolicyLabel = 
daoMgr.getXXPolicyLabels().create(xxPolicyLabel);
+                    }
                 }
-            }
 
-            if (xxPolicyLabel != null) {
-                XXPolicyLabelMap xxPolicyLabelMap = new XXPolicyLabelMap();
+                if (xxPolicyLabel != null) {

Review Comment:
   Sure, will remove it, it seems redundant.



-- 
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: dev-unsubscr...@ranger.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to