public RangerTagResourceMap preCreateTagResourceMap(String tagGuid, String resourceGuid) throws Exception { if (StringUtils.isBlank(resourceGuid) || StringUtils.isBlank(tagGuid)) { throw new Exception("Both resourceGuid and resourceId need to be non-empty"); } RangerTagResourceMap existing = tagStore.getTagResourceMapForTagAndResourceGuid(tagGuid, resourceGuid); if (existing != null) { throw new Exception( "Attempt to create existing association between resourceId=" + resourceGuid + " and tagId=" + tagGuid); } RangerServiceResource existingServiceResource = tagStore.getServiceResourceByGuid(resourceGuid); if (existingServiceResource == null) { throw new Exception("No resource found for guid=" + resourceGuid); } RangerTag existingTag = tagStore.getTagByGuid(tagGuid); if (existingTag == null) { throw new Exception("No tag found for guid=" + tagGuid); } RangerTagResourceMap newTagResourceMap = new RangerTagResourceMap(); newTagResourceMap.setResourceId(existingServiceResource.getId()); newTagResourceMap.setTagId(existingTag.getId()); return newTagResourceMap; }
public RangerTagResourceMap preDeleteTagResourceMap(String tagGuid, String resourceGuid) throws Exception { RangerTagResourceMap existing = tagStore.getTagResourceMapForTagAndResourceGuid(tagGuid, resourceGuid); if (existing == null) { throw new Exception( "Attempt to delete nonexistent association between resourceId=" + resourceGuid + " and tagId=" + tagGuid); } return existing; }