Class AbstractCrudController<T,U,R,F,Q extends SearchRequest<T>,ID>

java.lang.Object
nl.datasteel.crudcraft.runtime.controller.AbstractCrudController<T,U,R,F,Q,ID>
Type Parameters:
T - the JPA entity type
U - the upsert/patch request DTO type
R - the full response DTO type
F - the reference DTO type
Q - the search request type extending SearchRequest<T>
ID - the identifier type

public abstract class AbstractCrudController<T,U,R,F,Q extends SearchRequest<T>,ID> extends Object
Generic abstract REST controller exposing a full suite of CRUD endpoints.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    Maximum number of rows for CSV export.
    protected int
    Maximum number of rows for JSON export.
    protected int
    Maximum page size for pagination.
    protected int
    Maximum number of rows for XLSX export.
    protected final AbstractCrudService<T,U,R,F,ID>
    The service that handles CRUD operations.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructor to initialize the controller with the service.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.springframework.data.domain.Pageable
    clampPageable(org.springframework.data.domain.Pageable pageable)
    Clamps the pageable parameters to ensure they do not exceed the maximum page size.
    org.springframework.http.ResponseEntity<Map<String,Long>>
    Count total.
    org.springframework.http.ResponseEntity<R>
    create(U request)
    Create new.
    org.springframework.http.ResponseEntity<List<R>>
    createAll(@Valid List<U> requests)
    Bulk create.
    org.springframework.http.ResponseEntity<Void>
    delete(ID id)
    Delete.
    org.springframework.http.ResponseEntity<Void>
    Bulk delete.
    org.springframework.http.ResponseEntity<Void>
    exists(ID id)
    Exists check.
    org.springframework.http.ResponseEntity<org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody>
    export(Q searchRequest, Integer limit, String format)
    Export search results as CSV, JSON or XLSX.
    org.springframework.http.ResponseEntity<List<R>>
    Find by multiple IDs.
    org.springframework.http.ResponseEntity<PaginatedResponse<R>>
    getAll(org.springframework.data.domain.Pageable pageable, Q searchRequest)
    Paginated list (optional search).
    org.springframework.http.ResponseEntity<PaginatedResponse<F>>
    getAllRef(org.springframework.data.domain.Pageable pageable, Q searchRequest)
    Paginated list of reference DTOs.
    org.springframework.http.ResponseEntity<R>
    getById(ID id)
    Find by ID.
    org.springframework.http.ResponseEntity<R>
    patch(ID id, U request)
    Partial update.
    org.springframework.http.ResponseEntity<List<R>>
    patchAll(@Valid List<Identified<ID,U>> requests)
    Bulk patch.
    org.springframework.http.ResponseEntity<List<R>>
    search(Q searchRequest, Integer limit)
    Dedicated search endpoint.
    org.springframework.http.ResponseEntity<R>
    update(ID id, U request)
    Full update.
    org.springframework.http.ResponseEntity<List<R>>
    updateAll(@Valid List<Identified<ID,U>> requests)
    Bulk update.
    org.springframework.http.ResponseEntity<List<R>>
    upsertAll(Collection<U> requests)
    Bulk upsert.
    org.springframework.http.ResponseEntity<Void>
    validate(U request)
    Validate an upsert request body without persisting.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • service

      protected final AbstractCrudService<T,U,R,F,ID> service
      The service that handles CRUD operations.
    • maxPageSize

      @Value("${crudcraft.api.max-page-size:100}") protected int maxPageSize
      Maximum page size for pagination. Default is 100, can be overridden in application properties.
    • maxCsvRows

      @Value("${crudcraft.export.max-csv-rows:100000}") protected int maxCsvRows
      Maximum number of rows for CSV export. Default is 100,000, can be overridden in application properties.
    • maxJsonRows

      @Value("${crudcraft.export.max-json-rows:50000}") protected int maxJsonRows
      Maximum number of rows for JSON export. Default is 50,000, can be overridden in application properties.
    • maxXlsxRows

      @Value("${crudcraft.export.max-xlsx-rows:25000}") protected int maxXlsxRows
      Maximum number of rows for XLSX export. Default is 25,000, can be overridden in application properties.
  • Constructor Details

    • AbstractCrudController

      protected AbstractCrudController(AbstractCrudService<T,U,R,F,ID> service)
      Constructor to initialize the controller with the service.
      Parameters:
      service - the service that handles CRUD operations
  • Method Details

    • clampPageable

      protected org.springframework.data.domain.Pageable clampPageable(org.springframework.data.domain.Pageable pageable)
      Clamps the pageable parameters to ensure they do not exceed the maximum page size. If pageable is null, defaults to the first page with the maximum page size.
      Parameters:
      pageable - the original pageable request
      Returns:
      a clamped pageable object
    • getAll

      @GetMapping public org.springframework.http.ResponseEntity<PaginatedResponse<R>> getAll(org.springframework.data.domain.Pageable pageable, @ModelAttribute Q searchRequest)
      Paginated list (optional search). GET /?page=...&size=...&q=...
    • getAllRef

      @GetMapping("/ref") public org.springframework.http.ResponseEntity<PaginatedResponse<F>> getAllRef(org.springframework.data.domain.Pageable pageable, @ModelAttribute Q searchRequest)
      Paginated list of reference DTOs. GET /ref?page=...&size=...&q=...
    • getById

      @GetMapping("/{id}") public org.springframework.http.ResponseEntity<R> getById(@PathVariable("id") ID id)
      Find by ID. GET /{id}
    • create

      @PostMapping public org.springframework.http.ResponseEntity<R> create(@Valid @RequestBody U request)
      Create new. POST /
    • update

      @PutMapping("/{id}") public org.springframework.http.ResponseEntity<R> update(@PathVariable("id") ID id, @Valid @RequestBody U request)
      Full update. PUT /{id}
    • patch

      @PatchMapping("/{id}") public org.springframework.http.ResponseEntity<R> patch(@PathVariable("id") ID id, @RequestBody U request)
      Partial update. PATCH /{id}
    • delete

      @DeleteMapping("/{id}") public org.springframework.http.ResponseEntity<Void> delete(@PathVariable("id") ID id)
      Delete. DELETE /{id}
    • createAll

      @PostMapping("/batch") public org.springframework.http.ResponseEntity<List<R>> createAll(@Valid @RequestBody @Valid List<U> requests)
      Bulk create. POST /batch
    • updateAll

      @PutMapping("/batch") public org.springframework.http.ResponseEntity<List<R>> updateAll(@Valid @RequestBody @Valid List<Identified<ID,U>> requests)
      Bulk update. PUT /batch
    • patchAll

      @PatchMapping("/batch") public org.springframework.http.ResponseEntity<List<R>> patchAll(@Valid @RequestBody @Valid List<Identified<ID,U>> requests)
      Bulk patch. PATCH /batch
    • upsertAll

      @PostMapping("/batch/upsert") public org.springframework.http.ResponseEntity<List<R>> upsertAll(@RequestBody Collection<U> requests)
      Bulk upsert. POST /batch/upsert
    • deleteAllByIds

      @DeleteMapping("/batch/delete") public org.springframework.http.ResponseEntity<Void> deleteAllByIds(@RequestBody Collection<ID> ids)
      Bulk delete. DELETE /batch/delete
    • exists

      @RequestMapping(value="/exists/{id}", method={HEAD,GET}) public org.springframework.http.ResponseEntity<Void> exists(@PathVariable("id") ID id)
      Exists check. HEAD /{id} or GET /exists/{id}
    • count

      @GetMapping("/count") public org.springframework.http.ResponseEntity<Map<String,Long>> count()
      Count total. GET /count
    • findByIds

      @PostMapping("/batch/ids") public org.springframework.http.ResponseEntity<List<R>> findByIds(@RequestBody Collection<ID> ids)
      Find by multiple IDs. POST /batch/ids
    • search

      @GetMapping("/search") public org.springframework.http.ResponseEntity<List<R>> search(@ModelAttribute Q searchRequest, @RequestParam(value="limit",required=true) Integer limit)
      Dedicated search endpoint. GET /search?limit=...
    • validate

      @PostMapping("/validate") public org.springframework.http.ResponseEntity<Void> validate(@Valid @RequestBody U request)
      Validate an upsert request body without persisting. POST /validate
    • export

      @GetMapping("/export") public org.springframework.http.ResponseEntity<org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody> export(@ModelAttribute Q searchRequest, @RequestParam(value="limit",required=false) Integer limit, @RequestParam(value="format",required=true) String format)
      Export search results as CSV, JSON or XLSX. GET /export