ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject [48/55] [abbrv] incubator-ranger git commit: RANGER-203: database service-store implementation
Date Tue, 17 Feb 2015 08:17:21 GMT
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/c928a415/security-admin/src/main/java/org/apache/ranger/service/RangerPolicyService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/RangerPolicyService.java
b/security-admin/src/main/java/org/apache/ranger/service/RangerPolicyService.java
new file mode 100644
index 0000000..0c4f99a
--- /dev/null
+++ b/security-admin/src/main/java/org/apache/ranger/service/RangerPolicyService.java
@@ -0,0 +1,152 @@
+package org.apache.ranger.service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ranger.db.XXAccessTypeDefDao;
+import org.apache.ranger.db.XXPolicyResourceDao;
+import org.apache.ranger.entity.XXAccessTypeDef;
+import org.apache.ranger.entity.XXPolicy;
+import org.apache.ranger.entity.XXPolicyConditionDef;
+import org.apache.ranger.entity.XXPolicyItem;
+import org.apache.ranger.entity.XXPolicyItemAccess;
+import org.apache.ranger.entity.XXPolicyItemCondition;
+import org.apache.ranger.entity.XXPolicyResource;
+import org.apache.ranger.entity.XXPolicyResourceMap;
+import org.apache.ranger.entity.XXResourceDef;
+import org.apache.ranger.plugin.model.RangerPolicy;
+import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem;
+import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess;
+import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemCondition;
+import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+
+@Service
+@Scope("singleton")
+public class RangerPolicyService extends RangerPolicyServiceBase<XXPolicy, RangerPolicy>
{
+
+	@Override
+	protected void validateForCreate(RangerPolicy vObj) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	protected void validateForUpdate(RangerPolicy vObj, XXPolicy entityObj) {
+		// TODO Auto-generated method stub
+		
+	}
+	
+	@Override
+	protected RangerPolicy populateViewBean(XXPolicy xPolicy) {
+		RangerPolicy vPolicy = super.populateViewBean(xPolicy);
+		
+		Map<String, RangerPolicyResource> resources = getResourcesForXXPolicy(xPolicy);
+		vPolicy.setResources(resources);
+		
+		List<RangerPolicyItem> policyItems = getPolicyItemListForXXPolicy(xPolicy);
+		vPolicy.setPolicyItems(policyItems);
+		
+		return vPolicy;
+	}
+	
+	public List<RangerPolicyItem> getPolicyItemListForXXPolicy(XXPolicy xPolicy) {
+		
+		List<RangerPolicyItem> policyItems = new ArrayList<RangerPolicyItem>();
+		List<XXPolicyItem> xPolicyItemList = daoMgr.getXXPolicyItem().findByPolicyId(xPolicy.getId());
+		
+		for(XXPolicyItem xPolItem : xPolicyItemList) {
+			RangerPolicyItem policyItem = populateXXToRangerPolicyItem(xPolItem);
+			policyItems.add(policyItem);
+		}
+		return policyItems;
+	}
+
+	public RangerPolicyItem populateXXToRangerPolicyItem(XXPolicyItem xPolItem) {
+		
+		RangerPolicyItem rangerPolItem = new RangerPolicyItem();
+		
+		List<XXPolicyItemAccess> xPolItemAccList = daoMgr
+				.getXXPolicyItemAccess().findByPolicyItemId(xPolItem.getId());
+		List<RangerPolicyItemAccess> accesses = new ArrayList<RangerPolicyItemAccess>();
+		
+		XXAccessTypeDefDao xAccDefDao = daoMgr.getXXAccessTypeDef();
+		for(XXPolicyItemAccess xPolAccess : xPolItemAccList) {
+			RangerPolicyItemAccess access = new RangerPolicyItemAccess();
+			access.setIsAllowed(xPolAccess.getIsallowed());
+			XXAccessTypeDef xAccessType = xAccDefDao.getById(xPolAccess.getType());
+			access.setType(xAccessType.getName());
+			
+			accesses.add(access);
+		}
+		rangerPolItem.setAccesses(accesses);
+		
+		List<RangerPolicyItemCondition> conditions = new ArrayList<RangerPolicyItemCondition>();
+		List<XXPolicyConditionDef> xConditionDefList = daoMgr
+				.getXXPolicyConditionDef()
+				.findByPolicyItemId(xPolItem.getId());
+		for(XXPolicyConditionDef xCondDef : xConditionDefList) {
+			
+			List<XXPolicyItemCondition> xPolCondItemList = daoMgr
+					.getXXPolicyItemCondition().findByPolicyItemAndDefId(
+							xPolItem.getId(), xCondDef.getId());
+			List<String> values = new ArrayList<String>();
+			
+			for(XXPolicyItemCondition polCond : xPolCondItemList) {
+				values.add(polCond.getValue());
+			}
+			
+			RangerPolicyItemCondition condition = new RangerPolicyItemCondition();
+			condition.setType(xCondDef.getName());
+			condition.setValues(values);
+			
+			conditions.add(condition);
+		}
+		rangerPolItem.setConditions(conditions);
+		
+		List<String> userList = daoMgr.getXXUser().findByPolicyItemId(xPolItem.getId());
+		List<String> grpList = daoMgr.getXXGroup().findByPolicyItemId(xPolItem.getId());
+		
+		rangerPolItem.setUsers(userList);
+		rangerPolItem.setGroups(grpList);
+		
+		rangerPolItem.setDelegateAdmin(xPolItem.getDelegateAdmin());
+		return rangerPolItem;
+	}
+
+	public Map<String, RangerPolicyResource> getResourcesForXXPolicy(XXPolicy xPolicy)
{
+		List<XXResourceDef> resDefList = daoMgr.getXXResourceDef().findByPolicyId(xPolicy.getId());
+		Map<String, RangerPolicyResource> resources = new HashMap<String, RangerPolicyResource>();
+		
+		XXPolicyResourceDao xPolResDao = daoMgr.getXXPolicyResource();
+		for(XXResourceDef xResDef : resDefList) {
+			XXPolicyResource xPolRes = xPolResDao.findByResDefIdAndPolicyId(
+					xResDef.getId(), xPolicy.getId());
+			if(xPolRes == null) {
+				continue;
+			}
+			List<String> values = new ArrayList<>();
+			List<XXPolicyResourceMap> xPolResMapList = daoMgr
+					.getXXPolicyResourceMap()
+					.findByPolicyResId(xPolRes.getId());
+			for(XXPolicyResourceMap xPolResMap : xPolResMapList) {
+				values.add(xPolResMap.getValue());
+			}
+			RangerPolicyResource resource = new RangerPolicyResource();
+			resource.setValues(values);
+			resource.setIsExcludes(xPolRes.getIsexcludes());
+			resource.setIsRecursive(xPolRes.getIsrecursive());
+			
+			resources.put(xResDef.getName(), resource);
+		}
+		return resources;
+	}
+	
+	public RangerPolicy getPopulatedViewObject(XXPolicy xPolicy) {
+		return this.populateViewBean(xPolicy);
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/c928a415/security-admin/src/main/java/org/apache/ranger/service/RangerPolicyServiceBase.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..cf784cc
--- /dev/null
+++ b/security-admin/src/main/java/org/apache/ranger/service/RangerPolicyServiceBase.java
@@ -0,0 +1,49 @@
+package org.apache.ranger.service;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.ranger.common.GUIDUtil;
+import org.apache.ranger.common.MessageEnums;
+import org.apache.ranger.entity.XXPolicy;
+import org.apache.ranger.entity.XXService;
+import org.apache.ranger.plugin.model.RangerPolicy;
+
+public abstract class RangerPolicyServiceBase<T extends XXPolicy, V extends RangerPolicy>
extends RangerBaseModelService<T, V> {
+	
+	@Override
+	@SuppressWarnings("unchecked")
+	protected XXPolicy mapViewToEntityBean(RangerPolicy vObj, XXPolicy xObj, int OPERATION_CONTEXT)
{
+		String guid = (StringUtils.isEmpty(vObj.getGuid())) ? GUIDUtil.genGUI() : vObj.getGuid();
+		
+		xObj.setGuid(guid);
+		xObj.setVersion(vObj.getVersion());
+		
+		XXService xService = daoMgr.getXXService().findByName(vObj.getService());
+		if(xService == null) {
+			throw restErrorUtil.createRESTException(
+					"No corresponding service found for policyName: "
+							+ vObj.getName() + "Service Not Found : "
+							+ vObj.getName(), MessageEnums.INVALID_INPUT_DATA);
+		}
+		xObj.setService(xService.getId());
+		xObj.setName(vObj.getName());
+		xObj.setDescription(vObj.getDescription());
+		xObj.setIsAuditEnabled(vObj.getIsAuditEnabled());
+		xObj.setIsEnabled(vObj.getIsEnabled());
+		
+		return xObj;
+	}
+
+	@Override
+	@SuppressWarnings("unchecked")
+	protected RangerPolicy mapEntityToViewBean(RangerPolicy vObj, XXPolicy xObj) {
+		XXService xService = daoMgr.getXXService().getById(xObj.getService());
+		vObj.setGuid(xObj.getGuid());
+		vObj.setVersion(xObj.getVersion());
+		vObj.setService(xService.getName());
+		vObj.setName(xObj.getName());
+		vObj.setDescription(xObj.getDescription());
+		vObj.setIsEnabled(xObj.getIsEnabled());
+		vObj.setIsAuditEnabled(xObj.getIsAuditEnabled());
+		return vObj;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/c928a415/security-admin/src/main/java/org/apache/ranger/service/RangerServiceDefService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/RangerServiceDefService.java
b/security-admin/src/main/java/org/apache/ranger/service/RangerServiceDefService.java
new file mode 100644
index 0000000..4a79505
--- /dev/null
+++ b/security-admin/src/main/java/org/apache/ranger/service/RangerServiceDefService.java
@@ -0,0 +1,111 @@
+package org.apache.ranger.service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ranger.entity.XXAccessTypeDef;
+import org.apache.ranger.entity.XXEnumDef;
+import org.apache.ranger.entity.XXPolicyConditionDef;
+import org.apache.ranger.entity.XXResourceDef;
+import org.apache.ranger.entity.XXServiceConfigDef;
+import org.apache.ranger.entity.XXServiceDef;
+import org.apache.ranger.plugin.model.RangerServiceDef;
+import org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef;
+import org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef;
+import org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef;
+import org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef;
+import org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef;
+import org.apache.ranger.plugin.util.SearchFilter;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+
+@Service
+@Scope("singleton")
+public class RangerServiceDefService extends RangerServiceDefServiceBase<XXServiceDef,
RangerServiceDef> {
+
+	@Override
+	protected void validateForCreate(RangerServiceDef vObj) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	protected void validateForUpdate(RangerServiceDef vObj,
+			XXServiceDef entityObj) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	protected RangerServiceDef populateViewBean(XXServiceDef xServiceDef) {
+		RangerServiceDef serviceDef = super.populateViewBean(xServiceDef);
+		Long serviceDefId = xServiceDef.getId();
+		
+		List<XXServiceConfigDef> xConfigs = daoMgr.getXXServiceConfigDef().findByServiceDefId(serviceDefId);
+		if (!stringUtil.isEmpty(xConfigs)) {
+			List<RangerServiceConfigDef> configs = new ArrayList<RangerServiceConfigDef>();
+			for (XXServiceConfigDef xConfig : xConfigs) {
+				RangerServiceConfigDef config = populateXXToRangerServiceConfigDef(xConfig);
+				configs.add(config);
+			}
+			serviceDef.setConfigs(configs);
+		}
+		
+		List<XXResourceDef> xResources = daoMgr.getXXResourceDef().findByServiceDefId(serviceDefId);
+		if(!stringUtil.isEmpty(xResources)) {
+			List<RangerResourceDef> resources = new ArrayList<RangerResourceDef>();
+			for(XXResourceDef xResource : xResources) {
+				RangerResourceDef resource = populateXXToRangerResourceDef(xResource);
+				resources.add(resource);
+			}
+			serviceDef.setResources(resources);
+		}
+		
+		List<XXAccessTypeDef> xAccessTypes = daoMgr.getXXAccessTypeDef().findByServiceDefId(serviceDefId);
+		if(!stringUtil.isEmpty(xAccessTypes)) {
+			List<RangerAccessTypeDef> accessTypes = new ArrayList<RangerAccessTypeDef>();
+			for(XXAccessTypeDef xAtd : xAccessTypes) {
+				RangerAccessTypeDef accessType = populateXXToRangerAccessTypeDef(xAtd);
+				accessTypes.add(accessType);
+			}
+			serviceDef.setAccessTypes(accessTypes);
+		}
+		
+		List<XXPolicyConditionDef> xPolicyConditions = daoMgr.getXXPolicyConditionDef().findByServiceDefId(serviceDefId);
+		if(!stringUtil.isEmpty(xPolicyConditions)) {
+			List<RangerPolicyConditionDef> policyConditions = new ArrayList<RangerServiceDef.RangerPolicyConditionDef>();
+			for(XXPolicyConditionDef xPolicyCondDef : xPolicyConditions) {
+				RangerPolicyConditionDef policyCondition = populateXXToRangerPolicyConditionDef(xPolicyCondDef);
+				policyConditions.add(policyCondition);
+			}
+			serviceDef.setPolicyConditions(policyConditions);
+		}
+		
+		List<XXEnumDef> xEnumList = daoMgr.getXXEnumDef().findByServiceDefId(serviceDefId);
+		if(!stringUtil.isEmpty(xEnumList)) {
+			List<RangerEnumDef> enums = new ArrayList<RangerEnumDef>();
+			for(XXEnumDef xEnum : xEnumList) {
+				RangerEnumDef vEnum = populateXXToRangerEnumDef(xEnum);
+				enums.add(vEnum);
+			}
+			serviceDef.setEnums(enums);
+		}
+		return serviceDef;
+	}
+	
+	public List<RangerServiceDef> getServiceDefs(SearchFilter filter) {
+		List<XXServiceDef> xxServiceDefList = daoMgr.getXXServiceDef().getAll();
+		List<RangerServiceDef> serviceDefList = new ArrayList<RangerServiceDef>();
+		
+		for(XXServiceDef xxServiceDef : xxServiceDefList) {
+			RangerServiceDef serviceDef = populateViewBean(xxServiceDef);
+			serviceDefList.add(serviceDef);
+		}
+		return serviceDefList;
+	}
+	
+	public RangerServiceDef getPopulatedViewObject(XXServiceDef xServiceDef) {
+		return this.populateViewBean(xServiceDef);
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/c928a415/security-admin/src/main/java/org/apache/ranger/service/RangerServiceDefServiceBase.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/RangerServiceDefServiceBase.java
b/security-admin/src/main/java/org/apache/ranger/service/RangerServiceDefServiceBase.java
new file mode 100644
index 0000000..c96370b
--- /dev/null
+++ b/security-admin/src/main/java/org/apache/ranger/service/RangerServiceDefServiceBase.java
@@ -0,0 +1,257 @@
+package org.apache.ranger.service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ranger.common.AppConstants;
+import org.apache.ranger.common.GUIDUtil;
+import org.apache.ranger.common.MessageEnums;
+import org.apache.ranger.entity.XXAccessTypeDef;
+import org.apache.ranger.entity.XXDBBase;
+import org.apache.ranger.entity.XXEnumDef;
+import org.apache.ranger.entity.XXEnumElementDef;
+import org.apache.ranger.entity.XXPolicyConditionDef;
+import org.apache.ranger.entity.XXResourceDef;
+import org.apache.ranger.entity.XXServiceConfigDef;
+import org.apache.ranger.entity.XXServiceDef;
+import org.apache.ranger.plugin.model.RangerServiceDef;
+import org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef;
+import org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef;
+import org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumElementDef;
+import org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef;
+import org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef;
+import org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public abstract class RangerServiceDefServiceBase<T extends XXServiceDef, V extends RangerServiceDef>
+		extends RangerBaseModelService<T, V> {
+	private static final Log LOG = LogFactory.getLog(RangerServiceDefServiceBase.class);
+
+	@Autowired
+	RangerAuditFields<XXDBBase> rangerAuditFields;
+	
+	@SuppressWarnings("unchecked")
+	@Override
+	protected XXServiceDef mapViewToEntityBean(RangerServiceDef vObj, XXServiceDef xObj, int
operationContext) {
+		
+		String guid = (StringUtils.isEmpty(vObj.getGuid())) ? GUIDUtil.genGUI() : vObj.getGuid();
+		
+		xObj.setGuid(guid);
+		xObj.setVersion(vObj.getVersion());
+		xObj.setName(vObj.getName());
+		xObj.setImplclassname(vObj.getImplClass());
+		xObj.setLabel(vObj.getLabel());
+		xObj.setDescription(vObj.getDescription());
+		xObj.setRbkeylabel(vObj.getRbKeyLabel());
+		xObj.setRbkeydescription(vObj.getRbKeyDescription());
+		xObj.setIsEnabled(vObj.getIsEnabled());
+		return xObj;
+	}
+
+	@SuppressWarnings("unchecked")
+	@Override
+	protected RangerServiceDef mapEntityToViewBean(RangerServiceDef vObj, XXServiceDef xObj)
{
+		vObj.setGuid(xObj.getGuid());
+		vObj.setVersion(xObj.getVersion());
+		vObj.setName(xObj.getName());
+		vObj.setImplClass(xObj.getImplclassname());
+		vObj.setLabel(xObj.getLabel());
+		vObj.setDescription(xObj.getDescription());
+		vObj.setRbKeyLabel(xObj.getRbkeylabel());
+		vObj.setRbKeyDescription(xObj.getRbkeydescription());
+		vObj.setIsEnabled(xObj.getIsEnabled());
+		return vObj;
+	}
+	
+	public XXServiceConfigDef populateRangerServiceConfigDefToXX(RangerServiceConfigDef vObj,
XXServiceConfigDef xObj, XXServiceDef serviceDef) {
+		if(serviceDef == null) {
+			LOG.error("RangerServiceDefServiceBase.populateRangerServiceConfigDefToXX, serviceDef
can not be null");
+			throw restErrorUtil.createRESTException("RangerServiceDef cannot be null.", MessageEnums.DATA_NOT_FOUND);
+		}
+		
+		xObj = (XXServiceConfigDef) rangerAuditFields.populateAuditFields(xObj, serviceDef);
+		xObj.setDefid(serviceDef.getId());
+		xObj.setName(vObj.getName());
+		xObj.setType(vObj.getType());
+		xObj.setSubtype(vObj.getSubType());
+		xObj.setIsMandatory(vObj.getMandatory());
+		xObj.setDefaultvalue(vObj.getDefaultValue());
+		xObj.setLabel(vObj.getLabel());
+		xObj.setDescription(vObj.getDescription());
+		xObj.setRbkeylabel(vObj.getRbKeyLabel());
+		xObj.setRbkeydescription(vObj.getRbKeyDescription());
+		xObj.setOrder(AppConstants.DEFAULT_SORT_ORDER);
+		return xObj;
+	}
+
+	public RangerServiceConfigDef populateXXToRangerServiceConfigDef(XXServiceConfigDef xObj)
{
+		RangerServiceConfigDef vObj = new RangerServiceConfigDef();
+		vObj.setName(xObj.getName());
+		vObj.setType(xObj.getType());
+		vObj.setSubType(xObj.getSubtype());
+		vObj.setMandatory(xObj.getIsMandatory());
+		vObj.setDefaultValue(xObj.getDefaultvalue());
+		vObj.setLabel(xObj.getLabel());
+		vObj.setDescription(xObj.getDescription());
+		vObj.setRbKeyLabel(xObj.getRbkeylabel());
+		vObj.setRbKeyDescription(xObj.getRbkeydescription());
+		return vObj;
+	}
+	
+	public XXResourceDef populateRangerResourceDefToXX(RangerResourceDef vObj, XXResourceDef
xObj, XXServiceDef serviceDef) {
+		if(serviceDef == null) {
+			LOG.error("RangerServiceDefServiceBase.populateRangerResourceDefToXX, serviceDef can not
be null");
+			throw restErrorUtil.createRESTException("RangerServiceDef cannot be null.", MessageEnums.DATA_NOT_FOUND);
+		}
+		xObj = (XXResourceDef) rangerAuditFields.populateAuditFields(xObj, serviceDef);
+		xObj.setDefid(serviceDef.getId());
+		xObj.setName(vObj.getName());
+		xObj.setType(vObj.getType());
+		xObj.setLevel(vObj.getLevel());
+		xObj.setMandatory(vObj.getMandatory());
+		xObj.setLookupsupported(vObj.getLookupSupported());
+		xObj.setRecursivesupported(vObj.getRecursiveSupported());
+		xObj.setExcludessupported(vObj.getExcludesSupported());
+		xObj.setMatcher(vObj.getMatcher());
+		xObj.setMatcheroptions(vObj.getMatcherOptions());
+		xObj.setLabel(vObj.getLabel());
+		xObj.setDescription(vObj.getDescription());
+		xObj.setRbkeylabel(vObj.getRbKeyLabel());
+		xObj.setRbkeydescription(vObj.getRbKeyDescription());
+		xObj.setOrder(AppConstants.DEFAULT_SORT_ORDER);
+		return xObj;
+	}
+	
+	public RangerResourceDef populateXXToRangerResourceDef(XXResourceDef xObj) {
+		RangerResourceDef vObj = new RangerResourceDef();
+		vObj.setName(xObj.getName());
+		vObj.setType(xObj.getType());
+		vObj.setLevel(xObj.getLevel());		
+		vObj.setMandatory(xObj.getMandatory());
+		vObj.setLookupSupported(xObj.getLookupsupported());
+		vObj.setRecursiveSupported(xObj.getRecursivesupported());
+		vObj.setExcludesSupported(xObj.getExcludessupported());
+		vObj.setMatcher(xObj.getMatcher());
+		vObj.setMatcherOptions(xObj.getMatcheroptions());
+		vObj.setLabel(xObj.getLabel());
+		vObj.setDescription(xObj.getDescription());
+		vObj.setRbKeyLabel(xObj.getRbkeylabel());
+		vObj.setRbKeyDescription(xObj.getRbkeydescription());
+		
+		XXResourceDef parent = daoMgr.getXXResourceDef().getById(xObj.getParent());
+		String parentName = (parent != null) ? parent.getName() : null;
+		vObj.setParent(parentName);
+		
+		return vObj;
+	}
+	
+	public XXAccessTypeDef populateRangerAccessTypeDefToXX(RangerAccessTypeDef vObj, XXAccessTypeDef
xObj, XXServiceDef serviceDef) {
+		if(serviceDef == null) {
+			LOG.error("RangerServiceDefServiceBase.populateRangerAccessTypeDefToXX, serviceDef can
not be null");
+			throw restErrorUtil.createRESTException("RangerServiceDef cannot be null.", MessageEnums.DATA_NOT_FOUND);
+		}
+		xObj = (XXAccessTypeDef) rangerAuditFields.populateAuditFields(xObj, serviceDef);
+		xObj.setDefid(serviceDef.getId());
+		xObj.setName(vObj.getName());
+		xObj.setLabel(vObj.getLabel());
+		xObj.setRbkeylabel(vObj.getRbKeyLabel());
+		xObj.setOrder(AppConstants.DEFAULT_SORT_ORDER);
+		return xObj;
+	}
+	
+	public RangerAccessTypeDef populateXXToRangerAccessTypeDef(XXAccessTypeDef xObj) {
+		RangerAccessTypeDef vObj = new RangerAccessTypeDef();
+		vObj.setName(xObj.getName());
+		vObj.setLabel(xObj.getLabel());
+		vObj.setRbKeyLabel(xObj.getRbkeylabel());
+		
+		List<String> impliedGrants = daoMgr.getXXAccessTypeDefGrants().findImpliedGrantsByATDId(xObj.getId());
+		vObj.setImpliedGrants(impliedGrants);
+		return vObj;
+	}
+	
+	public XXPolicyConditionDef populateRangerPolicyConditionDefToXX(RangerPolicyConditionDef
vObj, XXPolicyConditionDef xObj, XXServiceDef serviceDef) {
+		if(serviceDef == null) {
+			LOG.error("RangerServiceDefServiceBase.populateRangerPolicyConditionDefToXX, serviceDef
can not be null");
+			throw restErrorUtil.createRESTException("RangerServiceDef cannot be null.", MessageEnums.DATA_NOT_FOUND);
+		}
+		xObj = (XXPolicyConditionDef) rangerAuditFields.populateAuditFields(xObj, serviceDef);
+		xObj.setDefid(serviceDef.getId());
+		xObj.setName(vObj.getName());
+		xObj.setEvaluator(vObj.getEvaluator());
+		xObj.setEvaluatoroptions(vObj.getEvaluatorOptions());
+		xObj.setLabel(vObj.getLabel());
+		xObj.setDescription(vObj.getDescription());
+		xObj.setRbkeylabel(vObj.getRbKeyLabel());
+		xObj.setRbkeydescription(vObj.getRbKeyDescription());
+		xObj.setOrder(AppConstants.DEFAULT_SORT_ORDER);
+		return xObj;
+	}
+	
+	public RangerPolicyConditionDef populateXXToRangerPolicyConditionDef(XXPolicyConditionDef
xObj) {
+		RangerPolicyConditionDef vObj = new RangerPolicyConditionDef();
+		vObj.setName(xObj.getName());
+		vObj.setEvaluator(xObj.getEvaluator());
+		vObj.setEvaluatorOptions(xObj.getEvaluatoroptions());
+		vObj.setLabel(xObj.getLabel());
+		vObj.setDescription(xObj.getDescription());
+		vObj.setRbKeyLabel(xObj.getRbkeylabel());
+		vObj.setRbKeyDescription(xObj.getRbkeydescription());
+		return vObj;
+	}
+	
+	public XXEnumDef populateRangerEnumDefToXX(RangerEnumDef vObj, XXEnumDef xObj, XXServiceDef
serviceDef) {
+		if(serviceDef == null) {
+			LOG.error("RangerServiceDefServiceBase.populateRangerEnumDefToXX, serviceDef can not be
null");
+			throw restErrorUtil.createRESTException("RangerServiceDef cannot be null.", MessageEnums.DATA_NOT_FOUND);
+		}
+		xObj = (XXEnumDef) rangerAuditFields.populateAuditFields(xObj, serviceDef);
+		xObj.setDefid(serviceDef.getId());
+		xObj.setName(vObj.getName());
+		xObj.setDefaultindex(vObj.getDefaultIndex());
+		return xObj;
+	}
+	
+	public RangerEnumDef populateXXToRangerEnumDef(XXEnumDef xObj) {
+		RangerEnumDef vObj = new RangerEnumDef();
+		vObj.setName(xObj.getName());
+		vObj.setDefaultIndex(xObj.getDefaultindex());
+		
+		List<XXEnumElementDef> xElements = daoMgr.getXXEnumElementDef().findByEnumDefId(xObj.getId());
+		List<RangerEnumElementDef> elements = new ArrayList<RangerEnumElementDef>();
+		
+		for(XXEnumElementDef xEle : xElements) {
+			RangerEnumElementDef element = populateXXToRangerEnumElementDef(xEle);
+			elements.add(element);
+		}
+		vObj.setElements(elements);
+		
+		return vObj;
+	}
+	
+	public XXEnumElementDef populateRangerEnumElementDefToXX(RangerEnumElementDef vObj, XXEnumElementDef
xObj, XXEnumDef enumDef) {
+		if(enumDef == null) {
+			LOG.error("RangerServiceDefServiceBase.populateRangerEnumElementDefToXX, enumDef can not
be null");
+			throw restErrorUtil.createRESTException("enumDef cannot be null.", MessageEnums.DATA_NOT_FOUND);
+		}
+		xObj = (XXEnumElementDef) rangerAuditFields.populateAuditFields(xObj, enumDef);
+		xObj.setEnumdefid(enumDef.getId());
+		xObj.setName(vObj.getName());
+		xObj.setLabel(vObj.getLabel());
+		xObj.setRbkeylabel(vObj.getRbKeyLabel());
+		xObj.setOrder(AppConstants.DEFAULT_SORT_ORDER);
+		return xObj;
+	}
+	
+	public RangerEnumElementDef populateXXToRangerEnumElementDef(XXEnumElementDef xObj) {
+		RangerEnumElementDef vObj = new RangerEnumElementDef();
+		vObj.setName(xObj.getName());
+		vObj.setLabel(xObj.getLabel());
+		vObj.setRbKeyLabel(xObj.getRbkeylabel());
+		return vObj;
+	}
+	
+}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/c928a415/security-admin/src/main/java/org/apache/ranger/service/RangerServiceService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/RangerServiceService.java
b/security-admin/src/main/java/org/apache/ranger/service/RangerServiceService.java
new file mode 100644
index 0000000..c0cf23a
--- /dev/null
+++ b/security-admin/src/main/java/org/apache/ranger/service/RangerServiceService.java
@@ -0,0 +1,59 @@
+package org.apache.ranger.service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.ranger.entity.XXService;
+import org.apache.ranger.entity.XXServiceConfigMap;
+import org.apache.ranger.plugin.model.RangerService;
+import org.apache.ranger.plugin.util.SearchFilter;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+
+@Service
+@Scope("singleton")
+public class RangerServiceService extends RangerServiceServiceBase<XXService, RangerService>
{
+
+	@Override
+	protected void validateForCreate(RangerService vObj) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	protected void validateForUpdate(RangerService vService, XXService xService) {
+		
+	}
+	
+	@Override
+	protected RangerService populateViewBean(XXService xService) {
+		RangerService vService = super.populateViewBean(xService);
+		
+		HashMap<String, String> configs = new HashMap<String, String>();
+		List<XXServiceConfigMap> svcConfigMapList = daoMgr.getXXServiceConfigMap()
+				.findByServiceId(xService.getId());
+		for(XXServiceConfigMap svcConfMap : svcConfigMapList) {
+			configs.put(svcConfMap.getConfigkey(), svcConfMap.getConfigvalue());
+		}
+		vService.setConfigs(configs);
+		
+		return vService;
+	}
+	
+	public RangerService getPopulatedViewObject(XXService xService) {
+		return this.populateViewBean(xService);
+	}
+	
+	public List<RangerService> getServices(SearchFilter filter) {
+		List<XXService> xxServiceList = daoMgr.getXXService().getAll();
+		List<RangerService> serviceList = new ArrayList<RangerService>();
+		
+		for(XXService xxService : xxServiceList) {
+			RangerService service = populateViewBean(xxService);
+			serviceList.add(service);
+		}
+		return serviceList;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/c928a415/security-admin/src/main/java/org/apache/ranger/service/RangerServiceServiceBase.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/RangerServiceServiceBase.java
b/security-admin/src/main/java/org/apache/ranger/service/RangerServiceServiceBase.java
new file mode 100644
index 0000000..32823aa
--- /dev/null
+++ b/security-admin/src/main/java/org/apache/ranger/service/RangerServiceServiceBase.java
@@ -0,0 +1,49 @@
+package org.apache.ranger.service;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.ranger.common.GUIDUtil;
+import org.apache.ranger.common.MessageEnums;
+import org.apache.ranger.entity.XXService;
+import org.apache.ranger.entity.XXServiceDef;
+import org.apache.ranger.plugin.model.RangerService;
+
+public abstract class RangerServiceServiceBase<T extends XXService, V extends RangerService>
extends RangerBaseModelService<T, V> {
+	
+	@Override
+	@SuppressWarnings("unchecked")
+	protected XXService mapViewToEntityBean(RangerService vObj, XXService xObj, int OPERATION_CONTEXT)
{
+		String guid = (StringUtils.isEmpty(vObj.getGuid())) ? GUIDUtil.genGUI() : vObj.getGuid();
+		
+		xObj.setGuid(guid);
+		xObj.setVersion(vObj.getVersion());
+		
+		XXServiceDef xServiceDef = daoMgr.getXXServiceDef().findByName(vObj.getType());
+		if(xServiceDef == null) {
+			throw restErrorUtil.createRESTException(
+					"No ServiceDefinition found with name :" + vObj.getType(),
+					MessageEnums.INVALID_INPUT_DATA);
+		}
+		xObj.setType(xServiceDef.getId());
+		xObj.setName(vObj.getName());
+		xObj.setPolicyVersion(vObj.getPolicyVersion());
+		xObj.setPolicyUpdateTime(vObj.getPolicyUpdateTime());
+		xObj.setDescription(vObj.getDescription());
+		xObj.setIsEnabled(vObj.getIsEnabled());
+		return xObj;
+	}
+
+	@Override
+	@SuppressWarnings("unchecked")
+	protected RangerService mapEntityToViewBean(RangerService vObj, XXService xObj) {
+		XXServiceDef xServiceDef = daoMgr.getXXServiceDef().getById(xObj.getType());
+		vObj.setType(xServiceDef.getName());
+		vObj.setGuid(xObj.getGuid());
+		vObj.setVersion(xObj.getVersion());
+		vObj.setName(xObj.getName());
+		vObj.setDescription(xObj.getDescription());
+		vObj.setPolicyVersion(xObj.getPolicyVersion());
+		vObj.setPolicyUpdateTime(xObj.getPolicyUpdateTime());
+		return vObj;
+	}
+	
+}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/c928a415/security-admin/src/test/java/org/apache/ranger/plugin/store/RangerDBStore.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/plugin/store/RangerDBStore.java
b/security-admin/src/test/java/org/apache/ranger/plugin/store/RangerDBStore.java
new file mode 100644
index 0000000..295ab5c
--- /dev/null
+++ b/security-admin/src/test/java/org/apache/ranger/plugin/store/RangerDBStore.java
@@ -0,0 +1,9 @@
+package org.apache.ranger.plugin.store;
+
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class RangerDBStore {
+
+}


Mime
View raw message