public RangerTagResourceMap preCreateTagResourceMapByIds(Long tagId, Long resourceId) throws Exception { RangerTagResourceMap existing = tagStore.getTagResourceMapForTagAndResourceId(tagId, resourceId); if (existing != null) { throw new Exception( "Attempt to create existing association between resourceId=" + resourceId + " and tagId=" + tagId); } RangerServiceResource existingServiceResource = tagStore.getServiceResource(resourceId); if (existingServiceResource == null) { throw new Exception("No resource found for id=" + resourceId); } RangerTag existingTag = tagStore.getTag(tagId); if (existingTag == null) { throw new Exception("No tag found for id=" + tagId); } RangerTagResourceMap newTagResourceMap = new RangerTagResourceMap(); newTagResourceMap.setResourceId(resourceId); newTagResourceMap.setTagId(tagId); return newTagResourceMap; }
public RangerServiceResource preDeleteServiceResource(Long id) throws Exception { RangerServiceResource existing = tagStore.getServiceResource(id); if (existing == null) { throw new Exception("Attempt to delete nonexistent resource, id=" + id); } List<RangerTagResourceMap> associations = tagStore.getTagResourceMapsForResourceId(existing.getId()); if (CollectionUtils.isNotEmpty(associations)) { throw new Exception( "Attempt to delete serviceResource which is associated with a tag, id=" + id); } return existing; }
public void preUpdateServiceResource(Long id, RangerServiceResource resource) throws Exception { if (StringUtils.isBlank(resource.getServiceName()) || MapUtils.isEmpty(resource.getResourceElements())) { throw new Exception("No serviceName or resource in RangerServiceResource"); } if (id == null) { throw new Exception("Invalid/null id"); } RangerServiceResource existing = tagStore.getServiceResource(id); if (existing == null) { throw new Exception("Attempt to update nonexistent resource, id=" + id); } RangerServiceResourceSignature serializer = new RangerServiceResourceSignature(resource); resource.setId(existing.getId()); resource.setGuid(existing.getGuid()); resource.setResourceSignature(serializer.getSignature()); }