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 RangerTag preDeleteTag(Long id) throws Exception { if (id == null) { throw new Exception("Invalid/null id"); } RangerTag existing = tagStore.getTag(id); if (existing == null) { throw new Exception("Attempt to delete nonexistent tag, id=" + id); } List<RangerTagResourceMap> associations = tagStore.getTagResourceMapsForTagId(existing.getId()); if (CollectionUtils.isNotEmpty(associations)) { throw new Exception( "Attempt to delete tag which is associated with a service-resource, id=" + id); } return existing; }
public void preUpdateTag(final Long id, final RangerTag tag) throws Exception { if (StringUtils.isBlank(tag.getType())) { throw new Exception("Tag has no type"); } if (id == null) { throw new Exception("Invalid/null id"); } RangerTag existing = tagStore.getTag(id); if (existing == null) { throw new Exception("Attempt to update nonexistant tag, id=" + id); } tag.setId(existing.getId()); tag.setGuid(existing.getGuid()); }