spring-data-rest

Spring Data Rest: Security based projection

丶灬走出姿态 提交于 2019-11-27 17:32:40
I am using the current version of Spring Data Rest and Spring Data JPA and have following entity: public class User { @Id @GeneratedValue private Long id; private String name; private String password; private String email; ...getter/setter methods... } I am also using Spring Security . My User Repository: @RepositoryRestResource( collectionResourceRel = "user", path = "user", excerptProjection = UserSimpleProjection.class) public interface UserRepository extends PagingAndSortingRepository<User, Long> { } For Example: User 1 is logged in User 1 requests http://localhost:8080/user/1 - all fields

Spring Boot @WebIntegrationTest and TestRestTemplate - Is it possible to rollback test transactions?

北城余情 提交于 2019-11-27 16:44:39
问题 I have a Spring Boot application with Spring Data Rest and I use @WebIntegrationTest along with the TestRestTemplate in my integration tests. The base class for the tests looks something like this: @RunWith(SpringJUnit4ClassRunner.class) @ActiveProfiles(profiles = "test") @SpringApplicationConfiguration(classes = Application.class) @Transactional @TransactionConfiguration @WebIntegrationTest("server.port: 0") public abstract class IntegrationTest { ... } I was testing the creation of an

How to add links to Spring Data REST projections?

元气小坏坏 提交于 2019-11-27 16:39:04
问题 I have created a Spring Data Rest projection (not an excerpt projection) and need to add some links to it only as these links do not hold significance with other projections of same entity nor with the entity itself. How can we do this as far as I know using ResourceProcessor I can add links to only entities, is it possible to add links for only that projection ? 回答1: It seems it is possible just to create a ResourceProcessor dedicated to a projection and I could create 3 ResourceProcessors

How to make an advanced search with Spring Data REST?

拟墨画扇 提交于 2019-11-27 14:49:02
问题 My task is to make an advanced search with Spring Data REST. How can I implement it? I managed to make a method to do a simple search, like this one: public interface ExampleRepository extends CrudRepository<Example, UUID>{ @RestResource(path="searchByName", rel="searchByName") Example findByExampleName(@Param("example") String exampleName); } This example works perfectly if I have to go simply to the url: .../api/examples/search/searchByName?example=myExample But what I have to do if there

Expose all IDs when using Spring Data Rest

一笑奈何 提交于 2019-11-27 14:38:16
I'd like to expose all IDs using a Spring Rest interface. I know that per default an ID like this will not be exposed via the rest interface: @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(unique=true, nullable=false) private Long id; I'm aware that I can use this to expose the ID for User : @Configuration public class RepositoryConfig extends RepositoryRestMvcConfiguration { @Override protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { config.exposeIdsFor(User.class); } } But is there an easy way to expose all IDs without manually

Why is an excerpt projection not applied automatically for a Spring Data REST item resource?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 13:36:55
I made a projection which should expose nested entities: @Projection(name = "inlineBusiness", types = { UserModel.class }) public interface InlineBusinessUserModelProjection { String getUsername(); String getFirstName(); String getLastName(); Date getBirthdate(); String getEmail(); BusinessModel getBusiness(); } And the service repository: @RepositoryRestResource(collectionResourceRel = "users", path = "users", excerptProjection = InlineBusinessUserModelProjection.class) public interface UserRepository extends BaseDAO<UserModel> {..} for /users it works fine, the business field is exposed with

Spring-Data-Rest Validator

坚强是说给别人听的谎言 提交于 2019-11-27 13:01:22
问题 I have been trying to add spring validators to a spring-data-rest project. I followed along and setup the "getting started" application via this link: http://spring.io/guides/gs/accessing-data-rest/ ...and now I am trying to add a custom PeopleValidator by following the documents here: http://docs.spring.io/spring-data/rest/docs/2.1.0.RELEASE/reference/html/validation-chapter.html My custom PeopleValidator looks like package hello; import org.springframework.validation.Errors; import org

Can JSR 303 Bean Validation be used with Spring Data Rest?

馋奶兔 提交于 2019-11-27 12:42:48
问题 I understand from the docs http://docs.spring.io/spring-data/rest/docs/2.1.2.RELEASE/reference/html/validation-chapter.html that I can declare validators with certain prefixes. I'm using JSR 303 so my domain entities are annotated with validation annotations. Can - and if yes, how - I use JSR 303 Bean Validation with Spring Data Rest? PS: I'm using Spring Boot 回答1: This seems to work: @Configuration protected static class CustomRepositoryRestMvcConfiguration extends

How to consume Page<Entity> response using Spring RestTemplate

混江龙づ霸主 提交于 2019-11-27 12:39:33
I'm using spring data (mongoDb) and I've got my repository: public interface StoriesRepository extends PagingAndSortingRepository<Story, String> {} Then i have a controller: @RequestMapping(method = RequestMethod.GET) public ResponseEntity<Page<StoryResponse>> getStories(Pageable pageable) { Page<StoryResponse> stories = storiesRepository.findAll(pageable).map(StoryResponseMapper::toStoryResponse); return ResponseEntity.ok(stories); } Everything works fine, but I can't consume my endpoint using RestTemplate getForEntity method: def entity = restTemplate.getForEntity(getLocalhost("/story"), new

Spring Data Rest - Sort by multiple properties

老子叫甜甜 提交于 2019-11-27 10:26:36
问题 I have an entity as below Class Person{ String id; String name; String numberOfHands; } With Spring Data Rest (Gosling Release Train), I'm able to specify localhost/Person?sort=name,asc for sorting name name ascending. Now, in a case where I need to sort by numberOfHands descending and name ascending. I'm able to specify localhost/Person?sort=numberOfHands,name,asc But, I'm not able to specify localhost/Person?sort=numberOfHands,desc,name,asc Is there a way to specify multiple sort order?