Class PetsRest
- All Implemented Interfaces:
jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,Serializable,BasicUniversalConfig,DefaultConfig,DefaultHtmlConfig
pets as p<petId> and o<orderId>. The Pending changes page is the
ChangesRest child.
Example:
<@card type="datatables" id="pets"> { dataMode:'server', dataUrl:'/console/pets/query', columns:[{key:'name', label:'Name'}, ...] } </@card>
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.juneau.rest.server.servlet.RestServlet
RestServlet.Builder<R extends RestServlet,SELF extends RestServlet.Builder<R, SELF>>, RestServlet.DefaultBuilder<R extends RestServlet> -
Field Summary
Fields inherited from class org.apache.juneau.petstore.console.PetstoreConsolePage
PAGE_HEADER, TEMPLATESFields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEAD -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreate(RestRequest req, JsonMap body) Creates a pet.delete(RestRequest req, long id) Deletes a pet.detail(RestRequest req, long id) The bare pet URL; lands on the first tab.detailOrder(RestRequest req, RestResponse res, long id, long orderId) P4 at nav depth 4: the Orders tab with one of this pet's orders selected.detailTab(RestRequest req, RestResponse res, long id, String tab) P4, one tab.The add/edit dialog form.historyRows(long id) orderDetail(long id, long orderId) The Orders tab's row-detail GET.orderRows(long id) page(RestRequest req) The Pets page.query(DataTablesRequest req, String ids) Server-mode DataTables query over all pets.protected Petrequire(long id) row(long id) sell(RestRequest req, long id) Marks a pet sold.sold(RestRequest req) The Sold pets page.soldRows()stage(RestRequest req, long id, JsonMap body) Stages an inline edit for review on the Pending changes page.update(RestRequest req, long id, JsonMap body) Replaces a pet.Methods inherited from class org.apache.juneau.petstore.console.PetstoreConsolePage
builder, freemarker, store, twinMethods inherited from class org.apache.juneau.rest.server.servlet.RestServlet
builder, createAuthenticator, destroy, doLog, getContext, getPath, getPaths, getRequest, getResponse, getRestBuilder, init, log, log, service, setContextMethods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPatch, doPost, doPut, doTrace, getLastModified, isSensitiveHeader, serviceMethods inherited from class jakarta.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Constructor Details
-
PetsRest
public PetsRest()
-
-
Method Details
-
page
The Pets page.- Parameters:
req- The request;?mixedrenders the half-FTL variant,?builderthe builder twin.- Returns:
- The page.
-
sold
The Sold pets page.- Parameters:
req- The request;?builderrenders the builder twin.- Returns:
- The page.
-
soldRows
- Returns:
- The client-mode rows for the Sold page: every sold pet, by id.
-
form
The add/edit dialog form.- Parameters:
id- The pet to edit, ornull to add.- Returns:
- The modal.
- Throws:
NotFound- Ifidnames no pet.
-
query
public DataTablesResults<Pet> query(@Content DataTablesRequest req, @Query("ids") @Schema(aev=true) String ids) Server-mode DataTables query over all pets.The optional
idsquery parameter (comma-separated pet ids, as theidsURL-state directive sends it) narrows the pets to those ids, before the request's own column filters apply, so the two combine. Tokens that are not numbers are dropped, and a blank value or one with no usable token is ignored.- Parameters:
req- The DataTables request.ids- The ids to keep, ornull.- Returns:
- One page of pets, or a 200
errorenvelope for a malformed search expression.
-
create
Creates a pet. Status defaults toAVAILABLE.- Parameters:
req- The request (write gate, audit actor).body- The new pet, either as the plain pet or as the dialog envelope{fields:{...}}.- Returns:
- The result toast, carrying the stored pet.
- Throws:
BadRequest- On a blank name or negative price.
-
update
Replaces a pet. Name and price are required; a species, tags or photo left out of the body keep their current values, as does the status.- Parameters:
req- The request.id- The pet id.body- The new state, either as the plain pet or as the dialog envelope{fields:{...}}.- Returns:
- The result toast.
- Throws:
NotFound- If the pet does not exist.
-
delete
Deletes a pet.- Parameters:
req- The request.id- The pet id.- Returns:
- The result toast.
- Throws:
NotFound- If the pet does not exist.
-
sell
Marks a pet sold. The Pets page bulk "Mark sold (N)" action calls this per row. -
stage
Stages an inline edit for review on the Pending changes page. The pet itself is not changed until the change is applied.PendingChanges.stage(long, java.lang.String, java.lang.String, java.lang.String)owns which fields are stageable and its messages. The photo is deliberately not stageable: the pet detail Photo tab edits it directly through the API's ownPUT /petstore/pets/{id}/photo.- Parameters:
req- The request.id- The pet id.body-{field, value}, or the inline-edit envelope{fields:{<field>:value}}with exactly one field.- Returns:
successcarrying the newPendingChange.- Throws:
BadRequest- If the field is missing or not stageable, or the value is invalid.NotFound- If the pet does not exist.
-
orderRows
- Parameters:
id- The pet id.- Returns:
- This pet's orders (the related list), by id.
- Throws:
NotFound- If the pet does not exist.
-
historyRows
- Parameters:
id- The pet id.- Returns:
- The audit rows for this pet, oldest first.
- Throws:
NotFound- If the pet does not exist.
-
detail
The bare pet URL; lands on the first tab.- Parameters:
req- The request.id- The pet id.- Returns:
- A 303 to
/console/pets/{id}/summary.
-
detailTab
public View detailTab(RestRequest req, RestResponse res, @Path("id") long id, @Path("tab") String tab) P4, one tab.- Parameters:
req- The request (viewer roles).res- The response (404 status for the not-found card).id- The pet id.tab- One ofTABS.- Returns:
- The tab page, or the not-found card with a 404 status.
- Throws:
NotFound- If the tab is unknown.
-
detailOrder
public View detailOrder(RestRequest req, RestResponse res, @Path("id") long id, @Path("orderId") long orderId) P4 at nav depth 4: the Orders tab with one of this pet's orders selected.- Parameters:
req- The request.res- The response.id- The pet id.orderId- The order id.- Returns:
- The Orders tab with the order card, or the not-found card with a 404 status if the pet does not exist.
- Throws:
NotFound- If the order does not exist or is not this pet's.
-
row
- Parameters:
id- The pet id.- Returns:
- The Summary card's single row: this pet, as a one-element list (the card is client-mode).
- Throws:
NotFound- If the pet does not exist.
-
orderDetail
The Orders tab's row-detail GET.- Parameters:
id- The pet id.orderId- The order id.- Returns:
{contractVersion, fields}(seeRowDetail.response(Object)).- Throws:
NotFound- If the order does not exist or is not this pet's.
-
require
- Parameters:
id- The pet id.- Returns:
- The live pet.
- Throws:
NotFound- If it does not exist.
-