Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data Rest & Spring Data Envers: How to expose REST API for Repository that extends Revision Repository

I'm having a problem to expose RevisionRepository (Spring Data Envers) endpoints for my repository which extends RevisionRepository as below :

    @RepositoryRestResource(path = "disciplines", itemResourceRel = "disciplines")
    public interface DisciplineRepository extends
        RevisionRepository<Discipline, Integer, Integer>,
        CrudRepository<Discipline, Integer>{

        @RestResource(path = "findByName", rel = "findByName")
        List<Discipline> findByName(String name);

    }

Only findByName method is exposed, is there any other way to expose the methods in RevisionRepository? I've also tried to override those methods in DisciplineRepository but it doesn't work.

Thank You...

like image 472
Azli Cn Avatar asked Dec 10 '15 08:12

Azli Cn


People also ask

What is the use of Spring Data REST?

Spring Data REST builds on top of Spring Data repositories, analyzes your application's domain model and exposes hypermedia-driven HTTP resources for aggregates contained in the model.

Why is Spring Data REST not recommended in real world applications?

It is not recommended in real-world applications as you are exposing your database entities directly as REST Services. While designing RESTful services, the two most important things that we consider are the domain model and the consumers. But, while using Spring Data REST, none of these parameters are considered.

What is meant by Spring REST?

REST stands for REpresentational State Transfer. It is developed by Roy Thomas Fielding, who also developed HTTP. The main goal of RESTful web services is to make web services more effective. RESTful web services try to define services using the different concepts that are already present in HTTP.

Is Spring GOOD FOR REST API?

Advantages of using Spring BootIt allows you to create REST APIs with minimal configurations. A few benefits of using Spring Boot for your REST APIs include: No requirement for complex XML configurations. Embedded Tomcat server to run Spring Boot applications.


1 Answers

You'll have to write a custom controller method to implement this, something like the following:

@Autowired
private DisciplineRepository disciplineRepository; 

@RequestMapping(value = "/disciplines/{id}/changes", method = RequestMethod.GET)
public ResponseEntity<Resource<RevisionsObject>> getDisciplineRevisions(@PathVariable(value = "id")Discipline discipline) {
    if (discipline != null) {
        Revisions<Integer, Discipline> disciplineRevisions = disciplineRepository.findRevisions(discipline.getId());
        return new ResponseEntity<>(new Resource<>(disciplineRevisions), HttpStatus.OK);
    } else {
        throw new ResourceNotFoundException();
    }
}
like image 109
adam p Avatar answered Sep 28 '22 00:09

adam p