/*
   * (non-Javadoc)
   * @see org.springframework.data.rest.core.mapping.ResourceMappings#getSearchResourceMappings(java.lang.Class)
   */
  @Override
  public SearchResourceMappings getSearchResourceMappings(Class<?> domainType) {

    Assert.notNull(domainType, "Type must not be null!");

    if (searchCache.containsKey(domainType)) {
      return searchCache.get(domainType);
    }

    RepositoryInformation repositoryInformation =
        repositories.getRepositoryInformationFor(domainType);
    List<MethodResourceMapping> mappings = new ArrayList<MethodResourceMapping>();
    ResourceMetadata resourceMapping = getMetadataFor(domainType);

    if (resourceMapping.isExported()) {
      for (Method queryMethod : repositoryInformation.getQueryMethods()) {
        RepositoryMethodResourceMapping methodMapping =
            new RepositoryMethodResourceMapping(
                queryMethod, resourceMapping, repositoryInformation);
        if (methodMapping.isExported()) {
          mappings.add(methodMapping);
        }
      }
    }

    SearchResourceMappings searchResourceMappings = new SearchResourceMappings(mappings);
    searchCache.put(domainType, searchResourceMappings);
    return searchResourceMappings;
  }
  /**
   * Returns whether we have a {@link ResourceMapping} for the given type and it is exported.
   *
   * @param type
   * @return
   */
  public boolean exportsMappingFor(Class<?> type) {

    if (!hasMappingFor(type)) {
      return false;
    }

    ResourceMetadata metadata = getMappingFor(type);
    return metadata.isExported();
  }
  /**
   * Returns whether we export a top-level resource for the given path.
   *
   * @param path must not be {@literal null} or empty.
   * @return
   */
  public boolean exportsTopLevelResourceFor(String path) {

    Assert.hasText(path);

    for (ResourceMetadata metadata : cache.values()) {
      if (metadata.getPath().matches(path)) {
        return metadata.isExported();
      }
    }

    return false;
  }
  /**
   * Finds the name of the entity collection using the meta information.
   *
   * @param entityAnnot
   * @return the entity name/path
   */
  public static String findEntityCollectionNameName(ResourceMetadata meta) {
    String name;
    switch (meta.getType()) {
      case RELATIONSHIP:
        name = meta.getParentResource();
        break;
      default:
        // an entity so just get its id.
        name = meta.getUniqueId();
    }

    if (name.startsWith("/")) {
      name = name.substring(1);
    }
    return name;
  }