Exemplo n.º 1
0
  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;
  }
Exemplo n.º 2
0
  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;
  }