#92 Add special Resource subclass that is returned by listRepositories method so that ResourceProcessors can easily add links to it.
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
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;
|
||||
@@ -10,12 +7,13 @@ 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;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import static org.springframework.data.rest.repository.support.ResourceMappingUtils.getResourceMapping;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
@@ -25,15 +23,15 @@ public class RepositoryController extends AbstractRepositoryRestController {
|
||||
|
||||
@Autowired
|
||||
public RepositoryController(Repositories repositories,
|
||||
RepositoryRestConfiguration config,
|
||||
DomainClassConverter domainClassConverter,
|
||||
ConversionService conversionService,
|
||||
EntityLinks entityLinks) {
|
||||
RepositoryRestConfiguration config,
|
||||
DomainClassConverter domainClassConverter,
|
||||
ConversionService conversionService,
|
||||
EntityLinks entityLinks) {
|
||||
super(repositories,
|
||||
config,
|
||||
domainClassConverter,
|
||||
conversionService,
|
||||
entityLinks);
|
||||
config,
|
||||
domainClassConverter,
|
||||
conversionService,
|
||||
entityLinks);
|
||||
}
|
||||
|
||||
@RequestMapping(
|
||||
@@ -44,16 +42,15 @@ public class RepositoryController extends AbstractRepositoryRestController {
|
||||
}
|
||||
)
|
||||
@ResponseBody
|
||||
public Resource<?> listRepositories()
|
||||
throws ResourceNotFoundException {
|
||||
Resource<?> links = new Resource<Object>(emptyList());
|
||||
for(Class<?> domainType : repositories) {
|
||||
public RepositoryLinksResource listRepositories() throws ResourceNotFoundException {
|
||||
RepositoryLinksResource resource = new RepositoryLinksResource();
|
||||
for (Class<?> domainType : repositories) {
|
||||
ResourceMapping repoMapping = getResourceMapping(config, repositories.getRepositoryInformationFor(domainType));
|
||||
if(repoMapping.isExported()) {
|
||||
links.add(entityLinks.linkToCollectionResource(domainType));
|
||||
if (repoMapping.isExported()) {
|
||||
resource.add(entityLinks.linkToCollectionResource(domainType));
|
||||
}
|
||||
}
|
||||
return links;
|
||||
return resource;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import org.springframework.hateoas.Resources;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public class RepositoryLinksResource extends Resources<Object> {
|
||||
|
||||
public RepositoryLinksResource() {
|
||||
super(Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user