This is an automated email from the ASF dual-hosted git repository.

abhay pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git


The following commit(s) were added to refs/heads/master by this push:
     new 2b988a8  RANGER-2580: RangerPolicy.getServiceType API should return 
name of the service-type
2b988a8 is described below

commit 2b988a83638d36528a4690705435023bc1f9fcef
Author: Abhay Kulkarni <[email protected]>
AuthorDate: Thu Sep 19 14:25:29 2019 -0700

    RANGER-2580: RangerPolicy.getServiceType API should return name of the 
service-type
---
 .../apache/ranger/plugin/model/RangerPolicy.java   | 42 +++++++++++-----------
 .../apache/ranger/biz/RangerPolicyRetriever.java   |  7 +++-
 .../ranger/service/RangerPolicyServiceBase.java    |  4 ++-
 .../service/TestRangerPolicyServiceBase.java       |  8 ++++-
 4 files changed, 37 insertions(+), 24 deletions(-)

diff --git 
a/agents-common/src/main/java/org/apache/ranger/plugin/model/RangerPolicy.java 
b/agents-common/src/main/java/org/apache/ranger/plugin/model/RangerPolicy.java
index 31156f7..04c6e75 100644
--- 
a/agents-common/src/main/java/org/apache/ranger/plugin/model/RangerPolicy.java
+++ 
b/agents-common/src/main/java/org/apache/ranger/plugin/model/RangerPolicy.java
@@ -266,33 +266,33 @@ public class RangerPolicy extends RangerBaseModelObject 
implements java.io.Seria
                this.isAuditEnabled = isAuditEnabled == null ? Boolean.TRUE : 
isAuditEnabled;
        }
 
-        public String getServiceType() {
-                return serviceType;
-        }
+       public String getServiceType() {
+               return serviceType;
+       }
 
-        public void setServiceType(String serviceType) {
-                this.serviceType = serviceType;
-        }
+       public void setServiceType(String serviceType) {
+               this.serviceType = serviceType;
+       }
 
-        public List<String> getPolicyLabels() {
-                return policyLabels;
-        }
+       public List<String> getPolicyLabels() {
+               return policyLabels;
+       }
 
-        public void setPolicyLabels(List<String> policyLabels) {
-                if (this.policyLabels == null) {
-                        this.policyLabels = new ArrayList<>();
-                }
+       public void setPolicyLabels(List<String> policyLabels) {
+               if (this.policyLabels == null) {
+                       this.policyLabels = new ArrayList<>();
+               }
 
-                if (this.policyLabels == policyLabels) {
-                        return;
-                }
+               if (this.policyLabels == policyLabels) {
+                       return;
+               }
 
-                this.policyLabels.clear();
+               this.policyLabels.clear();
 
-                if (policyLabels != null) {
-                        this.policyLabels.addAll(policyLabels);
-                }
-        }
+               if (policyLabels != null) {
+                       this.policyLabels.addAll(policyLabels);
+               }
+       }
 
        /**
         * @return the resources
diff --git 
a/security-admin/src/main/java/org/apache/ranger/biz/RangerPolicyRetriever.java 
b/security-admin/src/main/java/org/apache/ranger/biz/RangerPolicyRetriever.java
index c3c25ce..f839ceb 100644
--- 
a/security-admin/src/main/java/org/apache/ranger/biz/RangerPolicyRetriever.java
+++ 
b/security-admin/src/main/java/org/apache/ranger/biz/RangerPolicyRetriever.java
@@ -39,6 +39,7 @@ import org.apache.ranger.entity.XXPolicyLabelMap;
 import org.apache.ranger.entity.XXPortalUser;
 import org.apache.ranger.entity.XXSecurityZone;
 import org.apache.ranger.entity.XXService;
+import org.apache.ranger.entity.XXServiceDef;
 import org.apache.ranger.plugin.model.RangerPolicy;
 import org.apache.ranger.plugin.model.RangerPolicy.RangerDataMaskPolicyItem;
 import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem;
@@ -472,6 +473,7 @@ public class RangerPolicyRetriever {
                final XXService              service;
                final ListIterator<XXPolicy> iterPolicy;
                final ListIterator<XXPolicyLabelMap> iterPolicyLabels;
+               final XXServiceDef           serviceDef;
 
                RetrieverContext(XXService xService) {
                        if (xService != null) {
@@ -486,10 +488,12 @@ public class RangerPolicyRetriever {
                                
lookupCache.setConditionNameMapping(daoMgr.getXXPolicyRefCondition().findUpdatedConditionNamesByService(serviceId));
 
                                this.service    = xService;
+                               this.serviceDef = 
daoMgr.getXXServiceDef().getById(xService.getType());
                                this.iterPolicy = 
daoMgr.getXXPolicy().findByServiceId(serviceId).listIterator();
                                this.iterPolicyLabels = 
daoMgr.getXXPolicyLabelMap().findByServiceId(serviceId).listIterator();
                        } else {
                                this.service    = null;
+                               this.serviceDef = null;
                                this.iterPolicy = null;
                                this.iterPolicyLabels = null;
                        }
@@ -507,6 +511,7 @@ public class RangerPolicyRetriever {
                        
lookupCache.setConditionNameMapping(daoMgr.getXXPolicyRefCondition().findUpdatedConditionNamesByPolicy(policyId));
 
                        this.service    = xService;
+                       this.serviceDef = 
daoMgr.getXXServiceDef().getById(xService.getType());
                        this.iterPolicy = asList(xPolicy).listIterator();
                        List<XXPolicyLabelMap> policyLabels = 
daoMgr.getXXPolicyLabelMap().findByPolicyId(policyId);
                        this.iterPolicyLabels = policyLabels != null ? 
policyLabels.listIterator() : null;
@@ -533,7 +538,7 @@ public class RangerPolicyRetriever {
                                                
ret.setVersion(xPolicy.getVersion());
                                                
ret.setPolicyType(xPolicy.getPolicyType() == null ? 
RangerPolicy.POLICY_TYPE_ACCESS : xPolicy.getPolicyType());
                                                
ret.setService(service.getName());
-                                               
ret.setServiceType(service.getType().toString());
+                                               
ret.setServiceType(serviceDef.getName());
                                                
ret.setZoneName(lookupCache.getSecurityZoneName(xPolicy.getZoneId()));
                                                
updatePolicyReferenceFields(ret);
                                                getPolicyLabels(ret);
diff --git 
a/security-admin/src/main/java/org/apache/ranger/service/RangerPolicyServiceBase.java
 
b/security-admin/src/main/java/org/apache/ranger/service/RangerPolicyServiceBase.java
index e1653da..bcbca09 100644
--- 
a/security-admin/src/main/java/org/apache/ranger/service/RangerPolicyServiceBase.java
+++ 
b/security-admin/src/main/java/org/apache/ranger/service/RangerPolicyServiceBase.java
@@ -29,6 +29,7 @@ import org.apache.ranger.common.SortField.SORT_ORDER;
 import org.apache.ranger.entity.XXPolicyBase;
 import org.apache.ranger.entity.XXSecurityZone;
 import org.apache.ranger.entity.XXService;
+import org.apache.ranger.entity.XXServiceDef;
 import org.apache.ranger.plugin.model.RangerPolicy;
 import org.apache.ranger.plugin.model.RangerSecurityZone;
 import org.apache.ranger.plugin.util.SearchFilter;
@@ -140,10 +141,11 @@ public abstract class RangerPolicyServiceBase<T extends 
XXPolicyBase, V extends
        @Override
        protected V mapEntityToViewBean(V vObj, T xObj) {
                XXService xService = 
daoMgr.getXXService().getById(xObj.getService());
+               XXServiceDef xServiceDef = 
daoMgr.getXXServiceDef().getById(xService.getType());
                vObj.setGuid(xObj.getGuid());
                vObj.setVersion(xObj.getVersion());
                vObj.setService(xService.getName());
-               vObj.setServiceType(xService.getType().toString());
+               vObj.setServiceType(xServiceDef.getName());
                vObj.setName(StringUtils.trim(xObj.getName()));
                vObj.setPolicyType(xObj.getPolicyType() == null ? 
RangerPolicy.POLICY_TYPE_ACCESS : xObj.getPolicyType());
                vObj.setPolicyPriority(xObj.getPolicyPriority() == null ? 
RangerPolicy.POLICY_PRIORITY_NORMAL : xObj.getPolicyPriority());
diff --git 
a/security-admin/src/test/java/org/apache/ranger/service/TestRangerPolicyServiceBase.java
 
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerPolicyServiceBase.java
index f2d6149..ff8e908 100644
--- 
a/security-admin/src/test/java/org/apache/ranger/service/TestRangerPolicyServiceBase.java
+++ 
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerPolicyServiceBase.java
@@ -30,8 +30,10 @@ import org.apache.ranger.common.RangerSearchUtil;
 import org.apache.ranger.common.UserSessionBase;
 import org.apache.ranger.db.RangerDaoManager;
 import org.apache.ranger.db.XXServiceDao;
+import org.apache.ranger.db.XXServiceDefDao;
 import org.apache.ranger.entity.XXPolicy;
 import org.apache.ranger.entity.XXService;
+import org.apache.ranger.entity.XXServiceDef;
 import org.apache.ranger.plugin.model.RangerPolicy;
 import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem;
 import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess;
@@ -210,13 +212,17 @@ public class TestRangerPolicyServiceBase {
        public void test3mapEntityToViewBean() {
                XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
                XXService xService = Mockito.mock(XXService.class);
+               XXServiceDefDao xServiceDefDao = 
Mockito.mock(XXServiceDefDao.class);
+               XXServiceDef xServiceDef = Mockito.mock(XXServiceDef.class);
                RangerPolicy rangerPolicy = rangerPolicy();
                XXPolicy policy = policy();
 
                Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
                
Mockito.when(xServiceDao.getById(policy.getService())).thenReturn(
                                xService);
-
+               
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
+               
Mockito.when(xServiceDefDao.getById(xService.getType())).thenReturn(
+                               xServiceDef);
                RangerPolicy dbRangerPolicy = policyService.mapEntityToViewBean(
                                rangerPolicy, policy);
 

Reply via email to