code: public static String getPrimaryType(Resource resource) {
          String result = null;
          if (resource != null) {
              if (resource instanceof JcrResource) {
                  // use the resource itself if it implements the JcrResource interface (maybe a version of a resource)
                  result = ((JcrResource) resource).getPrimaryType();
              } else {
                  Node node = resource.adaptTo(Node.class);
                  if (node != null) {
                      try {
                          NodeType type = node.getPrimaryNodeType();
                          if (type != null) {
                              result = type.getName();
                          }
                      } catch (RepositoryException ignore) {
                      }
                  }
                  if (result == null) {
                      ValueMap values = resource.adaptTo(ValueMap.class);
                      if (values != null) {
                          result = values.get(JcrConstants.JCR_PRIMARYTYPE, (String) null);
                      }
                  }
              }
          }
          return result;
      }
docs: retrieves the primary type of the resources node