Fix for DATAREST-72. ResourceMapping.isExported() is now considered for displaying the link to the repository or when building the metadata for the request. Now sends back a 404 when a repository is not exported and an attempt to access it is made.

This commit is contained in:
Jon Brisbin
2013-03-06 08:42:20 -06:00
parent 5f21071a5e
commit 4d8f009679
3 changed files with 9 additions and 2 deletions

View File

@@ -1,9 +1,11 @@
package org.springframework.data.rest.example.mongodb;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.rest.repository.annotation.RestResource;
/**
* @author Jon Brisbin
*/
@RestResource(exported = false)
public interface ProfileRepository extends CrudRepository<Profile, String> {
}

View File

@@ -1,12 +1,14 @@
package org.springframework.data.rest.webmvc;
import static java.util.Collections.*;
import static org.springframework.data.rest.repository.support.ResourceMappingUtils.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.repository.support.DomainClassConverter;
import org.springframework.data.repository.support.Repositories;
import org.springframework.data.rest.config.RepositoryRestConfiguration;
import org.springframework.data.rest.config.ResourceMapping;
import org.springframework.hateoas.EntityLinks;
import org.springframework.hateoas.Resource;
import org.springframework.stereotype.Controller;
@@ -46,7 +48,10 @@ public class RepositoryController extends AbstractRepositoryRestController {
throws ResourceNotFoundException {
Resource<?> links = new Resource<Object>(emptyList());
for(Class<?> domainType : repositories) {
links.add(entityLinks.linkToCollectionResource(domainType));
ResourceMapping repoMapping = getResourceMapping(config, repositories.getRepositoryInformationFor(domainType));
if(repoMapping.isExported()) {
links.add(entityLinks.linkToCollectionResource(domainType));
}
}
return links;
}

View File

@@ -48,7 +48,7 @@ class RepositoryRestRequest {
this.baseUri = baseUri;
this.repoInfo = repoInfo;
this.repoMapping = getResourceMapping(config, repoInfo);
if(null == repoMapping) {
if(null == repoMapping || !repoMapping.isExported()) {
this.repoLink = null;
this.repository = null;
this.repoMethodInvoker = null;