ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject [1/4] incubator-ranger git commit: RANGER-595: updated tag-store implementation; replaced externalId references with guid; service.tagVersion incremented on changes to tagging for the service-resources
Date Fri, 28 Aug 2015 21:56:00 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/tag-policy 83cb21e0b -> 303f7b702


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/303f7b70/security-admin/src/main/java/org/apache/ranger/service/RangerTagResourceMapService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/RangerTagResourceMapService.java
b/security-admin/src/main/java/org/apache/ranger/service/RangerTagResourceMapService.java
new file mode 100644
index 0000000..503df82
--- /dev/null
+++ b/security-admin/src/main/java/org/apache/ranger/service/RangerTagResourceMapService.java
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.ranger.common.SearchField;
+import org.apache.ranger.common.SearchField.DATA_TYPE;
+import org.apache.ranger.common.SearchField.SEARCH_TYPE;
+import org.apache.ranger.entity.XXTagResourceMap;
+import org.apache.ranger.plugin.model.RangerTagResourceMap;
+import org.apache.ranger.plugin.util.SearchFilter;
+import org.springframework.stereotype.Service;
+
+@Service
+public class RangerTagResourceMapService extends RangerTagResourceMapServiceBase<XXTagResourceMap,
RangerTagResourceMap> {
+
+	public RangerTagResourceMapService() {
+		searchFields.add(new SearchField(SearchFilter.TAG_DEF_ID, "obj.id", DATA_TYPE.INTEGER,
SEARCH_TYPE.FULL));
+		searchFields.add(new SearchField(SearchFilter.TAG_RESOURCE_ID, "obj.resourceId", DATA_TYPE.INTEGER,
SearchField.SEARCH_TYPE.FULL));
+		searchFields.add(new SearchField(SearchFilter.TAG_ID, "obj.tagId", DATA_TYPE.INTEGER, SearchField.SEARCH_TYPE.FULL));
+	}
+	
+	@Override
+	protected void validateForCreate(RangerTagResourceMap vObj) {
+
+	}
+
+	@Override
+	protected void validateForUpdate(RangerTagResourceMap vObj, XXTagResourceMap entityObj)
{
+
+	}
+
+	@Override
+	public RangerTagResourceMap postCreate(XXTagResourceMap tagResMap) {
+		RangerTagResourceMap ret = super.postCreate(tagResMap);
+
+		daoMgr.getXXTagResourceMap().updateServiceForTagUpdate(tagResMap.getTagId(), tagResMap.getUpdateTime());
+
+		return ret;
+	}
+
+	@Override
+	public RangerTagResourceMap postUpdate(XXTagResourceMap tagResMap) {
+		RangerTagResourceMap ret = super.postUpdate(tagResMap);
+
+		daoMgr.getXXTagResourceMap().updateServiceForTagUpdate(tagResMap.getTagId(), tagResMap.getUpdateTime());
+
+		return ret;
+	}
+
+	@Override
+	protected XXTagResourceMap preDelete(Long id) {
+		XXTagResourceMap tagResMap = super.preDelete(id);
+
+		if (tagResMap != null) {
+			daoMgr.getXXTagResourceMap().updateServiceForTagUpdate(tagResMap.getTagId(), tagResMap.getUpdateTime());
+		}
+
+		return tagResMap;
+	}
+
+	public RangerTagResourceMap getPopulatedViewObject(XXTagResourceMap xObj) {
+		return populateViewBean(xObj);
+	}
+
+
+	public List<RangerTagResourceMap> getByTagId(Long tagId) {
+		List<RangerTagResourceMap> ret = new ArrayList<RangerTagResourceMap>();
+
+		List<XXTagResourceMap> xxTagResourceMaps = daoMgr.getXXTagResourceMap().findByTagId(tagId);
+		
+		if(CollectionUtils.isNotEmpty(xxTagResourceMaps)) {
+			for(XXTagResourceMap xxTagResourceMap : xxTagResourceMaps) {
+				RangerTagResourceMap tagResourceMap = populateViewBean(xxTagResourceMap);
+
+				ret.add(tagResourceMap);
+			}
+		}
+
+		return ret;
+	}
+
+	public List<RangerTagResourceMap> getByTagGuid(String tagGuid) {
+		List<RangerTagResourceMap> ret = new ArrayList<RangerTagResourceMap>();
+
+		List<XXTagResourceMap> xxTagResourceMaps = daoMgr.getXXTagResourceMap().findByTagGuid(tagGuid);
+		
+		if(CollectionUtils.isNotEmpty(xxTagResourceMaps)) {
+			for(XXTagResourceMap xxTagResourceMap : xxTagResourceMaps) {
+				RangerTagResourceMap tagResourceMap = populateViewBean(xxTagResourceMap);
+
+				ret.add(tagResourceMap);
+			}
+		}
+
+		return ret;
+	}
+
+	public List<RangerTagResourceMap> getByResourceId(Long resourceId) {
+		List<RangerTagResourceMap> ret = new ArrayList<RangerTagResourceMap>();
+
+		List<XXTagResourceMap> xxTagResourceMaps = daoMgr.getXXTagResourceMap().findByResourceId(resourceId);
+		
+		if(CollectionUtils.isNotEmpty(xxTagResourceMaps)) {
+			for(XXTagResourceMap xxTagResourceMap : xxTagResourceMaps) {
+				RangerTagResourceMap tagResourceMap = populateViewBean(xxTagResourceMap);
+
+				ret.add(tagResourceMap);
+			}
+		}
+
+		return ret;
+	}
+
+	public List<RangerTagResourceMap> getByResourceGuid(String resourceGuid) {
+		List<RangerTagResourceMap> ret = new ArrayList<RangerTagResourceMap>();
+
+		List<XXTagResourceMap> xxTagResourceMaps = daoMgr.getXXTagResourceMap().findByResourceGuid(resourceGuid);
+		
+		if(CollectionUtils.isNotEmpty(xxTagResourceMaps)) {
+			for(XXTagResourceMap xxTagResourceMap : xxTagResourceMaps) {
+				RangerTagResourceMap tagResourceMap = populateViewBean(xxTagResourceMap);
+
+				ret.add(tagResourceMap);
+			}
+		}
+
+		return ret;
+	}
+	
+	public RangerTagResourceMap getByTagAndResourceId(Long tagId, Long resourceId) {
+		RangerTagResourceMap ret = null;
+
+		XXTagResourceMap xxTagResourceMap = daoMgr.getXXTagResourceMap().findByTagAndResourceId(tagId,
resourceId);
+
+		if(xxTagResourceMap != null) {
+			ret = populateViewBean(xxTagResourceMap);
+		}
+
+		return ret;
+	}
+
+	public RangerTagResourceMap getByTagAndResourceGuid(String tagGuid, String resourceGuid)
{
+		RangerTagResourceMap ret = null;
+
+		XXTagResourceMap xxTagResourceMap = daoMgr.getXXTagResourceMap().findByTagAndResourceGuid(tagGuid,
resourceGuid);
+
+		if(xxTagResourceMap != null) {
+			ret = populateViewBean(xxTagResourceMap);
+		}
+
+		return ret;
+	}
+
+	public List<RangerTagResourceMap> getTagResourceMapsByServiceId(Long serviceId) {
+		List<RangerTagResourceMap> ret = new ArrayList<RangerTagResourceMap>();
+
+		List<XXTagResourceMap> xxTagResourceMaps = daoMgr.getXXTagResourceMap().findByServiceId(serviceId);
+		
+		if(CollectionUtils.isNotEmpty(xxTagResourceMaps)) {
+			for(XXTagResourceMap xxTagResourceMap : xxTagResourceMaps) {
+				RangerTagResourceMap tagResourceMap = populateViewBean(xxTagResourceMap);
+
+				ret.add(tagResourceMap);
+			}
+		}
+
+		return ret;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/303f7b70/security-admin/src/main/java/org/apache/ranger/service/RangerTagResourceMapServiceBase.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/RangerTagResourceMapServiceBase.java
b/security-admin/src/main/java/org/apache/ranger/service/RangerTagResourceMapServiceBase.java
new file mode 100644
index 0000000..727cb79
--- /dev/null
+++ b/security-admin/src/main/java/org/apache/ranger/service/RangerTagResourceMapServiceBase.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.ranger.common.GUIDUtil;
+import org.apache.ranger.entity.XXTagResourceMap;
+import org.apache.ranger.plugin.model.RangerTagResourceMap;
+import org.apache.ranger.plugin.store.PList;
+import org.apache.ranger.plugin.util.SearchFilter;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public abstract class RangerTagResourceMapServiceBase<T extends XXTagResourceMap, V extends
RangerTagResourceMap> extends RangerBaseModelService<T, V> {
+
+	@Autowired
+	GUIDUtil guidUtil;
+
+	@Override
+	@SuppressWarnings("unchecked")
+	protected XXTagResourceMap mapViewToEntityBean(RangerTagResourceMap vObj, XXTagResourceMap
xObj, int operationContext) {
+		String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid();
+
+		xObj.setGuid(guid);
+		xObj.setTagId(vObj.getTagId());
+		xObj.setResourceId(vObj.getResourceId());
+
+		return xObj;
+	}
+
+	@Override
+	@SuppressWarnings("unchecked")
+	protected RangerTagResourceMap mapEntityToViewBean(RangerTagResourceMap vObj, XXTagResourceMap
xObj) {
+		vObj.setGuid(xObj.getGuid());
+		vObj.setTagId(xObj.getTagId());
+		vObj.setResourceId(xObj.getResourceId());
+
+		return vObj;
+	}
+
+	@SuppressWarnings("unchecked")
+	public PList<RangerTagResourceMap> searchRangerTaggedResources(SearchFilter searchFilter)
{
+		PList<RangerTagResourceMap> retList = new PList<RangerTagResourceMap>();
+		List<RangerTagResourceMap> taggedResList = new ArrayList<RangerTagResourceMap>();
+
+		List<XXTagResourceMap> xTaggedResList = (List<XXTagResourceMap>) searchRangerObjects(searchFilter,
searchFields, sortFields, (PList<V>) retList);
+
+		for (XXTagResourceMap xTaggedRes : xTaggedResList) {
+			RangerTagResourceMap taggedRes = populateViewBean((T) xTaggedRes);
+			taggedResList.add(taggedRes);
+		}
+		retList.setList(taggedResList);
+		return retList;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/303f7b70/security-admin/src/main/java/org/apache/ranger/service/RangerTagService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/RangerTagService.java
b/security-admin/src/main/java/org/apache/ranger/service/RangerTagService.java
index b5cb303..1251454 100644
--- a/security-admin/src/main/java/org/apache/ranger/service/RangerTagService.java
+++ b/security-admin/src/main/java/org/apache/ranger/service/RangerTagService.java
@@ -1,14 +1,15 @@
 package org.apache.ranger.service;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.ranger.common.SearchField;
 import org.apache.ranger.entity.XXTag;
 import org.apache.ranger.plugin.model.RangerTag;
 import org.apache.ranger.plugin.util.SearchFilter;
 import org.springframework.stereotype.Service;
 
-/**
- * Created by akulkarni on 8/19/15.
- */
 
 @Service
 public class RangerTagService extends RangerTagServiceBase<XXTag, RangerTag> {
@@ -32,4 +33,79 @@ public class RangerTagService extends RangerTagServiceBase<XXTag, RangerTag>
{
 		return populateViewBean(xObj);
 	}
 
+	public RangerTag getTagByGuid(String guid) {
+		RangerTag ret = null;
+
+		XXTag xxTag = daoMgr.getXXTag().findByGuid(guid);
+		
+		if(xxTag != null) {
+			ret = populateViewBean(xxTag);
+		}
+
+		return ret;
+	}
+
+	public List<RangerTag> getTagsByName(String name) {
+		List<RangerTag> ret = new ArrayList<RangerTag>();
+
+		List<XXTag> xxTags = daoMgr.getXXTag().findByName(name);
+		
+		if(CollectionUtils.isNotEmpty(xxTags)) {
+			for(XXTag xxTag : xxTags) {
+				RangerTag tag = populateViewBean(xxTag);
+
+				ret.add(tag);
+			}
+		}
+
+		return ret;
+	}
+
+	public List<RangerTag> getTagsForResourceId(Long resourceId) {
+		List<RangerTag> ret = new ArrayList<RangerTag>();
+
+		List<XXTag> xxTags = daoMgr.getXXTag().findForResourceId(resourceId);
+		
+		if(CollectionUtils.isNotEmpty(xxTags)) {
+			for(XXTag xxTag : xxTags) {
+				RangerTag tag = populateViewBean(xxTag);
+
+				ret.add(tag);
+			}
+		}
+
+		return ret;
+	}
+
+	public List<RangerTag> getTagsForResourceGuid(String resourceGuid) {
+		List<RangerTag> ret = new ArrayList<RangerTag>();
+
+		List<XXTag> xxTags = daoMgr.getXXTag().findForResourceGuid(resourceGuid);
+		
+		if(CollectionUtils.isNotEmpty(xxTags)) {
+			for(XXTag xxTag : xxTags) {
+				RangerTag tag = populateViewBean(xxTag);
+
+				ret.add(tag);
+			}
+		}
+
+		return ret;
+	}
+
+	public List<RangerTag> getTagsByServiceId(Long serviceId) {
+		List<RangerTag> ret = new ArrayList<RangerTag>();
+
+		List<XXTag> xxTags = daoMgr.getXXTag().findByServiceId(serviceId);
+		
+		if(CollectionUtils.isNotEmpty(xxTags)) {
+			for(XXTag xxTag : xxTags) {
+				RangerTag tag = populateViewBean(xxTag);
+
+				ret.add(tag);
+			}
+		}
+
+		return ret;
+	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/303f7b70/security-admin/src/main/java/org/apache/ranger/service/RangerTagServiceBase.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/RangerTagServiceBase.java
b/security-admin/src/main/java/org/apache/ranger/service/RangerTagServiceBase.java
index 7a9c9da..359e7ae 100644
--- a/security-admin/src/main/java/org/apache/ranger/service/RangerTagServiceBase.java
+++ b/security-admin/src/main/java/org/apache/ranger/service/RangerTagServiceBase.java
@@ -20,16 +20,18 @@
 package org.apache.ranger.service;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.ranger.common.GUIDUtil;
 import org.apache.ranger.common.RangerConfigUtil;
 import org.apache.ranger.entity.XXDBBase;
-import org.apache.ranger.entity.XXTagAttributeDef;
+import org.apache.ranger.entity.XXTagAttribute;
 import org.apache.ranger.entity.XXTag;
 import org.apache.ranger.plugin.model.RangerTag;
-import org.apache.ranger.plugin.model.RangerTagDef;
 import org.apache.ranger.plugin.store.PList;
 import org.apache.ranger.plugin.util.SearchFilter;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -52,8 +54,6 @@ public abstract class RangerTagServiceBase<T extends XXTag, V extends
RangerTag>
 		String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid();
 
 		xObj.setGuid(guid);
-		xObj.setVersion(vObj.getVersion());
-		xObj.setIsEnabled(vObj.getIsEnabled());
 		xObj.setName(vObj.getName());
 		return xObj;
 	}
@@ -63,22 +63,25 @@ public abstract class RangerTagServiceBase<T extends XXTag, V extends
RangerTag>
 	protected RangerTag mapEntityToViewBean(RangerTag vObj, XXTag xObj) {
 
 		vObj.setGuid(xObj.getGuid());
-		vObj.setVersion(xObj.getVersion());
-		vObj.setIsEnabled(xObj.getIsEnabled());
 		vObj.setName(xObj.getName());
 
+		Map<String, String> attributeValues = getAttributeValuesForTag(xObj);
+		vObj.setAttributeValues(attributeValues);
+
 		return vObj;
 	}
 
-	/**
-	 * @param xObj
-	 * @return
-	 */
-	public RangerTagDef.RangerTagAttributeDef populateRangerTagAttributeDef(XXTagAttributeDef
xObj) {
-		RangerTagDef.RangerTagAttributeDef attrDef = new RangerTagDef.RangerTagAttributeDef();
-		attrDef.setName(xObj.getName());
-		attrDef.setType(xObj.getType());
-		return attrDef;
+	public Map<String, String> getAttributeValuesForTag(XXTag xtag) {
+		List<XXTagAttribute> tagAttrList = daoMgr.getXXTagAttribute().findByTagId(xtag.getId());
+		Map<String, String>  ret         = new HashMap<String, String>();
+
+		if(CollectionUtils.isNotEmpty(tagAttrList)) {
+			for (XXTagAttribute tagAttr : tagAttrList) {
+				ret.put(tagAttr.getName(), tagAttr.getValue());
+			}
+		}
+
+		return ret;
 	}
 
 	@SuppressWarnings("unchecked")

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/303f7b70/security-admin/src/main/java/org/apache/ranger/service/RangerTaggedResourceService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/RangerTaggedResourceService.java
b/security-admin/src/main/java/org/apache/ranger/service/RangerTaggedResourceService.java
deleted file mode 100644
index 327a6b8..0000000
--- a/security-admin/src/main/java/org/apache/ranger/service/RangerTaggedResourceService.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.ranger.service;
-
-import org.apache.ranger.common.SearchField;
-import org.apache.ranger.common.SearchField.DATA_TYPE;
-import org.apache.ranger.common.SearchField.SEARCH_TYPE;
-import org.apache.ranger.entity.XXTaggedResource;
-import org.apache.ranger.plugin.model.RangerServiceResource;
-import org.apache.ranger.plugin.util.SearchFilter;
-import org.springframework.stereotype.Service;
-
-@Service
-public class RangerTaggedResourceService extends RangerTaggedResourceServiceBase<XXTaggedResource,
RangerServiceResource> {
-
-	public RangerTaggedResourceService() {
-		searchFields.add(new SearchField(SearchFilter.TAG_RESOURCE_ID, "obj.id", DATA_TYPE.INTEGER,
SEARCH_TYPE.FULL));
-	}
-
-	@Override
-	protected void validateForCreate(RangerServiceResource vObj) {
-
-	}
-
-	@Override
-	protected void validateForUpdate(RangerServiceResource vObj, XXTaggedResource entityObj)
{
-
-	}
-	
-	public RangerServiceResource getPopulatedViewObject(XXTaggedResource xObj) {
-		return populateViewBean(xObj);
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/303f7b70/security-admin/src/main/java/org/apache/ranger/service/RangerTaggedResourceServiceBase.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/RangerTaggedResourceServiceBase.java
b/security-admin/src/main/java/org/apache/ranger/service/RangerTaggedResourceServiceBase.java
deleted file mode 100644
index 5f97001..0000000
--- a/security-admin/src/main/java/org/apache/ranger/service/RangerTaggedResourceServiceBase.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.ranger.service;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.ranger.common.GUIDUtil;
-import org.apache.ranger.common.MessageEnums;
-import org.apache.ranger.entity.XXResourceDef;
-import org.apache.ranger.entity.XXService;
-import org.apache.ranger.entity.XXTaggedResource;
-import org.apache.ranger.entity.XXTaggedResourceValue;
-import org.apache.ranger.plugin.model.RangerPolicy;
-import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource;
-import org.apache.ranger.plugin.model.RangerServiceResource;
-import org.apache.ranger.plugin.store.PList;
-import org.apache.ranger.plugin.util.SearchFilter;
-import org.springframework.beans.factory.annotation.Autowired;
-
-public abstract class RangerTaggedResourceServiceBase<T extends XXTaggedResource, V extends
RangerServiceResource> extends RangerBaseModelService<T, V> {
-
-	@Autowired
-	GUIDUtil guidUtil;
-
-	@Override
-	@SuppressWarnings("unchecked")
-	protected XXTaggedResource mapViewToEntityBean(RangerServiceResource vObj, XXTaggedResource
xObj, int operationContext) {
-		String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid();
-
-		xObj.setGuid(guid);
-		xObj.setVersion(vObj.getVersion());
-		xObj.setIsEnabled(vObj.getIsEnabled());
-
-		XXService xService = daoMgr.getXXService().findByName(vObj.getServiceName());
-		if (xService == null) {
-			throw restErrorUtil.createRESTException("Error Populating XXTaggedResource. No Service
found with name: " + vObj.getServiceName(), MessageEnums.INVALID_INPUT_DATA);
-		}
-
-		xObj.setServiceId(xService.getId());
-
-		return xObj;
-	}
-
-	@Override
-	@SuppressWarnings("unchecked")
-	protected RangerServiceResource mapEntityToViewBean(RangerServiceResource vObj, XXTaggedResource
xObj) {
-		vObj.setGuid(xObj.getGuid());
-		vObj.setVersion(xObj.getVersion());
-		vObj.setIsEnabled(xObj.getIsEnabled());
-
-		XXService xService = daoMgr.getXXService().getById(xObj.getServiceId());
-
-		vObj.setServiceName(xService.getName());
-
-		List<XXTaggedResourceValue> resValueList = daoMgr.getXXTaggedResourceValue().findByTaggedResId(xObj.getId());
-		Map<String, RangerPolicy.RangerPolicyResource> resourceSpec = new HashMap<String,
RangerPolicy.RangerPolicyResource>();
-
-		for (XXTaggedResourceValue resValue : resValueList) {
-			List<String> resValueMapList = daoMgr.getXXTaggedResourceValueMap().findValuesByResValueId(resValue.getId());
-
-			XXResourceDef xResDef = daoMgr.getXXResourceDef().getById(resValue.getResDefId());
-
-			RangerPolicyResource policyRes = new RangerPolicyResource();
-			policyRes.setIsExcludes(resValue.getIsExcludes());
-			policyRes.setIsRecursive(resValue.getIsRecursive());
-			policyRes.setValues(resValueMapList);
-
-			resourceSpec.put(xResDef.getName(), policyRes);
-		}
-
-		vObj.setResourceSpec(resourceSpec);
-
-		return vObj;
-	}
-
-	@SuppressWarnings("unchecked")
-	public PList<RangerServiceResource> searchRangerTaggedResources(SearchFilter searchFilter)
{
-		PList<RangerServiceResource> retList = new PList<RangerServiceResource>();
-		List<RangerServiceResource> taggedResList = new ArrayList<RangerServiceResource>();
-
-		List<XXTaggedResource> xTaggedResList = (List<XXTaggedResource>) searchRangerObjects(searchFilter,
searchFields, sortFields, (PList<V>) retList);
-
-		for (XXTaggedResource xTaggedRes : xTaggedResList) {
-			RangerServiceResource taggedRes = populateViewBean((T) xTaggedRes);
-			taggedResList.add(taggedRes);
-		}
-		retList.setList(taggedResList);
-		return retList;
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/303f7b70/security-admin/src/main/resources/META-INF/jpa_named_queries.xml
----------------------------------------------------------------------
diff --git a/security-admin/src/main/resources/META-INF/jpa_named_queries.xml b/security-admin/src/main/resources/META-INF/jpa_named_queries.xml
index 555dfb0..b8fd003 100644
--- a/security-admin/src/main/resources/META-INF/jpa_named_queries.xml
+++ b/security-admin/src/main/resources/META-INF/jpa_named_queries.xml
@@ -534,51 +534,125 @@
 	</named-query>
 	
 	<!-- Start ==> JPA Queries for Tag Based Policies  -->
-
-	<named-query name="XXTagAttributeDef.findByTagDefId">
-		<query>select obj from XXTagAttributeDef obj where obj.tagDefId = :tagDefId</query>
+	
+	<named-query name="XXServiceResourceElement.findByResourceId">
+		<query>select obj from XXServiceResourceElement obj where obj.resourceId = :resourceId</query>
 	</named-query>
 	
-	<named-query name="XXTaggedResourceValue.findByTaggedResId">
-		<query>select obj from XXTaggedResourceValue obj where obj.taggedResourceId = :taggedResId</query>
+	<named-query name="XXServiceResourceElementValue.findByResElementId">
+		<query>select obj from XXServiceResourceElementValue obj where obj.resElementId =
:resElementId</query>
+	</named-query>
+
+	<named-query name="XXServiceResourceElementValue.findValuesByResElementId">
+		<query>select obj.value from XXServiceResourceElementValue obj where obj.resElementId
= :resElementId</query>
+	</named-query>
+
+	<named-query name="XXTagResourceMap.findByResourceId">
+		<query>select obj from XXTagResourceMap obj where obj.resourceId = :resourceId</query>
+	</named-query>
+
+	<named-query name="XXTagResourceMap.findByResourceGuid">
+		<query>select obj from XXTagResourceMap obj, XXServiceResource res where res.guid
= :resourceGuid and obj.resourceId = res.id</query>
 	</named-query>
 	
-	<named-query name="XXTaggedResourceValueMap.findByResValueId">
-		<query>select obj from XXTaggedResourceValueMap obj where obj.resValueId = :resValueId</query>
+	<named-query name="XXTagResourceMap.findByTagId">
+		<query>select obj from XXTagResourceMap obj where obj.tagId = :tagId</query>
+	</named-query>
+
+	<named-query name="XXTagResourceMap.findByTagGuid">
+		<query>select obj from XXTagResourceMap obj, XXTag tag where tag.guid = :tagGuid
and obj.tagId = tag.id</query>
 	</named-query>
 
-	<named-query name="XXTaggedResourceValueMap.findValuesByResValueId">
-		<query>select obj.value from XXTaggedResourceValueMap obj where obj.resValueId =
:resValueId</query>
+	<named-query name="XXTagResourceMap.findByTagAndResourceId">
+		<query>select obj from XXTagResourceMap obj where obj.resourceId = :resourceId and
obj.tagId = :tagId</query>
 	</named-query>
 
-	<named-query name="XXTag.findByTaggedResource">
-		<query>select obj from XXTag obj, XXTagResourceMap tagResMap where 
-		tagResMap.taggedResId = :taggedResId and obj.id = tagResMap.tagId</query>
+	<named-query name="XXTagResourceMap.findByTagAndResourceGuid">
+		<query>select obj from XXTagResourceMap obj, XXTag tag, XXServiceResource res where
tag.guid = :tagGuid and res.guid = :resourceGuid and obj.tagId = tag.id and obj.resourceId
= res.id</query>
 	</named-query>
+
+	<named-query name="XXTagResourceMap.findByServiceId">
+		<query>select obj from XXTagResourceMap obj, XXServiceResource res
+				where obj.resourceId = res.id and res.serviceId = :serviceId
+				order by obj.resourceId</query>
+	</named-query>
+
+	<named-query name="XXTagResourceMap.updateTagVersionInService">
+		<query>update XXService obj set obj.tagVersion = obj.tagVersion + 1, obj.tagUpdateTime
= :tagUpdateTime
+				where obj.id in (select res.serviceId from XXServiceResource res, XXTagResourceMap tagRes,
XXTag tag
+								  where res.id = tagRes.resourceId and tagRes.tagId = tag.id and tag.id = :tagId)</query>
+	</named-query>	
 	
-	<named-query name="XXTagAttribute.findByTagId">
-		<query>select obj from XXTagAttribute obj where obj.tagId = :tagId</query>
+	<named-query name="XXTagDef.findByGuid">
+		<query>select obj from XXTagDef obj where obj.guid = :guid</query>
+	</named-query>
+	
+	<named-query name="XXTagDef.findByName">
+		<query>select obj from XXTagDef obj where obj.name = :name</query>
+	</named-query>
+	
+	<named-query name="XXTagDef.findByServiceId">
+		<query>select obj from XXTagDef obj where obj.name in
+				(select tag.name from XXTag tag, XXTagResourceMap tagRes, XXServiceResource resource
where tag.id = tagRes.tagId and tagRes.resourceId = resource.id and resource.serviceId = :serviceId)</query>
+	</named-query>
+
+	<named-query name="XXTagDef.updateTagVersionInService">
+		<query>update XXService obj set obj.tagVersion = obj.tagVersion + 1, obj.tagUpdateTime
= :tagUpdateTime
+				where obj.id in (select res.serviceId from XXServiceResource res, XXTagResourceMap tagRes,
XXTag tag, XXTagDef tagDef
+								  where res.id = tagRes.resourceId and tagRes.tagId = tag.id and tag.name = tagDef.name
and tagDef.id = :tagDefId)</query>
+	</named-query>	
+
+	<named-query name="XXTagAttributeDef.findByTagDefId">
+		<query>select obj from XXTagAttributeDef obj where obj.tagDefId = :tagDefId</query>
+	</named-query>
+
+	
+	<named-query name="XXTag.findByGuid">
+		<query>select obj from XXTag obj where obj.guid = :guid</query>
 	</named-query>
 	
-	<named-query name="XXTaggedResource.findByServiceId">
-		<query>select obj from XXTaggedResource obj where obj.serviceId = :serviceId</query>
+	<named-query name="XXTag.findByName">
+		<query>select obj from XXTag obj where obj.name = :name</query>
+	</named-query>
+
+	<named-query name="XXTag.findByResourceId">
+		<query>select obj from XXTag obj, XXTagResourceMap tagResMap where tagResMap.resourceId
= :resourceId and obj.id = tagResMap.tagId</query>
+	</named-query>
+
+	<named-query name="XXTag.findByResourceGuid">
+		<query>select obj from XXTag obj, XXTagResourceMap tagRes, XXServiceResource res
where res.guid = :resourceGuid and res.id = tagRes.resourceId and tagRes.tagId = obj.id</query>
 	</named-query>
 
 	<named-query name="XXTag.findTagNamesByServiceId">
-		<query>select obj.name from XXTag obj, XXTaggedResource tRes, XXTagResourceMap tResMap
where 
-		tRes.serviceId = :serviceId and obj.id = tResMap.tagId and tRes.id = tResMap.taggedResId
</query>
+		<query>select obj.name from XXTag obj, XXServiceResource tRes, XXTagResourceMap tResMap
where 
+		tRes.serviceId = :serviceId and obj.id = tResMap.tagId and tRes.id = tResMap.resourceId
</query>
 	</named-query>	
 	
-	<named-query name="XXTagResourceMap.findByTaggedResourceId">
-		<query>select obj from XXTagResourceMap obj where obj.taggedResId = :taggedResId</query>
+	<named-query name="XXTag.findByServiceId">
+		<query>select obj from XXTag obj where obj.id in
+			(select tagRes.tagId from XXTagResourceMap tagRes, XXServiceResource resource where tagRes.resourceId
= resource.id and resource.serviceId = :serviceId)</query>
+	</named-query>
+	
+	<named-query name="XXTagAttribute.findByTagId">
+		<query>select obj from XXTagAttribute obj where obj.tagId = :tagId</query>
+	</named-query>
+
+
+	<named-query name="XXServiceResource.findByGuid">
+		<query>select obj from XXServiceResource obj where obj.guid = :guid</query>
 	</named-query>
 	
-	<named-query name="XXTag.findTagsByExternalId">
-		<query>select obj from XXTag obj where obj.externalId = :externalId</query>
+	<named-query name="XXServiceResource.findByServiceId">
+		<query>select obj from XXServiceResource obj where obj.serviceId = :serviceId</query>
 	</named-query>
 	
-	<named-query name="XXTagDef.findByName">
-		<query>select obj from XXTagDef obj where obj.name = :name</query>
+	<named-query name="XXServiceResource.findTaggedResourcesInServiceId">
+		<query>select obj from XXServiceResource obj where obj.serviceId = :serviceId and
obj.id in
+					(select tagResMap.resourceId from XXTagResourceMap tagResMap)</query>
+	</named-query>
+
+	<named-query name="XXServiceResource.findByServiceIdAndResourceSignature">
+		<query>select obj from XXServiceResource obj where obj.serviceId = :serviceId and
obj.resourceSignature = :resourceSignature</query>
 	</named-query>
 
 	<!-- End <== JPA Queries for Tag Based Policies  -->


Mime
View raw message