Class ListHalMethodImplementor

    • Constructor Detail

      • ListHalMethodImplementor

        public ListHalMethodImplementor​(boolean isResteasyClassic,
                                        boolean isReactivePanache)
    • 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 exposes RestDataResource.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 null Page instance is used.
         
             @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);
                 }
            }
         
         
        The RESTEasy Reactive version exposes ReactiveRestDataResource.list(Page, Sort) and the generated code looks more or less like this:
         
             &#64;GET
             &#64;Path("")
             &#64;Produces({"application/hal+json"})
             public Uni<Response> listHal(@QueryParam("page") @DefaultValue("0") int pageIndex,
                     &#64;QueryParam("size") @DefaultValue("20") int pageSize,
                     &#64;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:
        implementInternal in class StandardMethodImplementor