Class ListHalMethodImplementor
- java.lang.Object
-
- io.quarkus.rest.data.panache.deployment.methods.StandardMethodImplementor
-
- io.quarkus.rest.data.panache.deployment.methods.hal.HalMethodImplementor
-
- io.quarkus.rest.data.panache.deployment.methods.hal.ListHalMethodImplementor
-
- All Implemented Interfaces:
MethodImplementor
public final class ListHalMethodImplementor extends HalMethodImplementor
-
-
Field Summary
-
Fields inherited from class io.quarkus.rest.data.panache.deployment.methods.StandardMethodImplementor
responseImplementor
-
Fields inherited from interface io.quarkus.rest.data.panache.deployment.methods.MethodImplementor
APPLICATION_HAL_JSON, APPLICATION_JSON
-
-
Constructor Summary
Constructors Constructor Description ListHalMethodImplementor(boolean isResteasyClassic, boolean isReactivePanache)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringgetResourceMethodName()Get a name of a method which this controller uses to access data.protected voidimplementInternal(io.quarkus.gizmo.ClassCreator classCreator, ResourceMetadata resourceMetadata, ResourceProperties resourceProperties, io.quarkus.gizmo.FieldDescriptor resourceField)Generate HAL JAX-RS GET method.-
Methods inherited from class io.quarkus.rest.data.panache.deployment.methods.hal.HalMethodImplementor
implement, wrapHalEntities
-
Methods inherited from class io.quarkus.rest.data.panache.deployment.methods.StandardMethodImplementor
addConsumesAnnotation, addContextAnnotation, addDefaultValueAnnotation, addDeleteAnnotation, addGetAnnotation, addLinksAnnotation, addPathAnnotation, addPathParamAnnotation, addPostAnnotation, addProducesAnnotation, addProducesJsonAnnotation, addPutAnnotation, addQueryParamAnnotation, addSortQueryParamValidatorAnnotation, appendToPath, implementTryBlock, isNotReactivePanache, isResteasyClassic
-
-
-
-
Method Detail
-
implementInternal
protected void implementInternal(io.quarkus.gizmo.ClassCreator classCreator, ResourceMetadata resourceMetadata, ResourceProperties resourceProperties, io.quarkus.gizmo.FieldDescriptor resourceField)Generate HAL JAX-RS GET method. The RESTEasy Classic version exposesRestDataResource.list(Page, Sort)via HAL JAX-RS method. Generated pseudocode with enabled pagination is shown below. If pagination is disabled pageIndex and pageSize query parameters are skipped and nullPageinstance is used.
The RESTEasy Reactive version exposes@GET @Path("") @Produces({"application/hal+json"}) public Response listHal(@QueryParam("page") @DefaultValue("0") int pageIndex, @QueryParam("size") @DefaultValue("20") int pageSize, @QueryParam("sort") String sortQuery) { Page page = Page.of(pageIndex, pageSize); Sort sort = ...; // Build a sort instance by parsing a query param try { List<Entity> entities = resource.getAll(page, sort); // Get the page count, and build first, last, next, previous page instances HalCollectionWrapper wrapper = new HalCollectionWrapper(entities, Entity.class, "entities"); // Add first, last, next and previous page URIs to the wrapper if they exist Response.ResponseBuilder responseBuilder = Response.status(200); responseBuilder.entity(wrapper); // Add headers with first, last, next and previous page URIs if they exist return responseBuilder.build(); } catch (Throwable t) { throw new RestDataPanacheException(t); } }ReactiveRestDataResource.list(Page, Sort)and the generated code looks more or less like this:@GET @Path("") @Produces({"application/hal+json"}) public Uni<Response> listHal(@QueryParam("page") @DefaultValue("0") int pageIndex, @QueryParam("size") @DefaultValue("20") int pageSize, @QueryParam("sort") String sortQuery) { Page page = Page.of(pageIndex, pageSize); Sort sort = ...; // Build a sort instance by parsing a query param resource.getAll(page, sort).map(entities -> { // Get the page count, and build first, last, next, previous page instances HalCollectionWrapper wrapper = new HalCollectionWrapper(entities, Entity.class, "entities"); // Add first, last, next and previous page URIs to the wrapper if they exist Response.ResponseBuilder responseBuilder = Response.status(200); responseBuilder.entity(wrapper); // Add headers with first, last, next and previous page URIs if they exist return responseBuilder.build(); }).onFailure().invoke(t -> throw new RestDataPanacheException(t)); }- Specified by:
implementInternalin classStandardMethodImplementor
-
getResourceMethodName
protected String getResourceMethodName()
Description copied from class:StandardMethodImplementorGet a name of a method which this controller uses to access data.- Specified by:
getResourceMethodNamein classStandardMethodImplementor
-
-