protected Resource toResource(PrivilegeEntity privilegeEntity,
                                Map<Long, UserEntity> userEntities,
                                Map<Long, GroupEntity> groupEntities,
                                Map<Long, PermissionEntity> roleEntities,
                                Map<Long, T> resourceEntities,
                                Set<String> requestedIds) {
    Resource resource = new ResourceImpl(resourceType);

    PrincipalEntity principal = privilegeEntity.getPrincipal();
    String principalTypeName = null;
    String resourcePropertyName = null;

    if(principal != null) {
      PrincipalTypeEntity principalType = principal.getPrincipalType();

      if (principalType != null) {
        Long principalId = principal.getId();

        principalTypeName = principalType.getName();

        if (StringUtils.equalsIgnoreCase(PrincipalTypeEntity.GROUP_PRINCIPAL_TYPE_NAME, principalTypeName)) {
          GroupEntity groupEntity = groupEntities.get(principalId);
          if (groupEntity != null) {
            resourcePropertyName = groupEntity.getGroupName();
          }
        } else if (StringUtils.equalsIgnoreCase(PrincipalTypeEntity.ROLE_PRINCIPAL_TYPE_NAME, principalTypeName)) {
          PermissionEntity roleEntity = roleEntities.get(principalId);
          if (roleEntity != null) {
            resourcePropertyName = roleEntity.getPermissionName();
          }
        } else if (StringUtils.equalsIgnoreCase(PrincipalTypeEntity.USER_PRINCIPAL_TYPE_NAME, principalTypeName)) {
          UserEntity userEntity = userEntities.get(principalId);
          if (userEntity != null) {
            resourcePropertyName = userEntity.getUserName();
          }
        }
      }
    }

    setResourceProperty(resource, PRIVILEGE_ID, privilegeEntity.getId(), requestedIds);
    setResourceProperty(resource, PERMISSION_NAME, privilegeEntity.getPermission().getPermissionName(), requestedIds);
    setResourceProperty(resource, PERMISSION_LABEL, privilegeEntity.getPermission().getPermissionLabel(), requestedIds);
    setResourceProperty(resource, PRINCIPAL_NAME, resourcePropertyName, requestedIds);
    setResourceProperty(resource, PRINCIPAL_TYPE, principalTypeName, requestedIds);

    return resource;
  }
Convert the given privilege entity into a Resource.

@param privilegeEntity   the privilege entity to be converted
@param userEntities      the map of user entities keyed by resource id
@param groupEntities     the map of group entities keyed by resource id
@param roleEntities      the map of role entities keyed by resource id
@param resourceEntities  the map of resource entities keyed by resource id
@param requestedIds      the requested property ids

@return the resource
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PrivilegeResourceProvider.java