Class ChangesRest

java.lang.Object
jakarta.servlet.GenericServlet
All Implemented Interfaces:
jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable, BasicUniversalConfig, DefaultConfig, DefaultHtmlConfig

public class ChangesRest extends PetstoreConsolePage
Pending changes: the staged-edits table. Persistent selection is limited to PENDING rows, an aggregate Discard returns a BulkResult, a perRow Apply writes each change to its pet, and a perRow Retry re-applies a failed change. Also the data source of the header pending-changes badge.
Example:

selection: { rowIdField:'id', selectAll:true, scope:'persistent', labelField:'summary', selectableWhen:[{field:'state', op:'eq', value:'PENDING', reason:'Only pending changes can be discarded or applied.'}] }, bulk: { actions: [ { id:'discard', label:'Discard', bulkMode:'aggregate', endpoint:'/console/pets/changes/discard', method:'POST', tone:'danger' }, { id:'apply', label:'Apply', bulkMode:'perRow', endpoint:'/console/pets/changes/{id}/apply', method:'POST' } ] }

@RestPost(path="/discard") public BulkResult discard(RestRequest req, @Content BulkRequest body) { var o = store().pendingChanges().discard(body.ids, ConsoleWrites.actor(req)); var b = BulkResult.create().succeeded(o.succeeded().toArray(String[]::new)).notFound(...); o.failed().forEach(f -> b.failed(new BulkResult.Failure(f.id(), f.message()))); return b.build(); }

See Also:
  • Constructor Details

  • Method Details

    • page

      public View page(RestRequest req)
      The Pending changes page.
      Parameters:
      req - The request; ?builder renders the builder twin.
      Returns:
      The page.
    • query

      Server-mode DataTables query over staged changes.
      Parameters:
      req - The DataTables request.
      Returns:
      One page of changes, or a 200 error envelope for a malformed search expression.
    • pending

      public JsonMap pending(RestRequest req)
      The header badge source: pending changes, flagged mine for the caller.
      Parameters:
      req - The request.
      Returns:
      {total, mine, items:[{id,label,href,mine,kind}]}.
    • apply

      public ActionResult apply(RestRequest req, @Path("id") long id)
      Applies one change (the bulk perRow action).
      Parameters:
      req - The request.
      id - The change id.
      Returns:
      success with the change when applied, failure with the reason when the write failed.
      Throws:
      NotFound - If the change does not exist.
      Conflict - If it is not pending.
    • retry

      public ActionResult retry(RestRequest req, @Path("id") long id)
      Retries a failed change.
      Parameters:
      req - The request.
      id - The change id.
      Returns:
      As apply(RestRequest, long).
      Throws:
      NotFound - If the change does not exist.
      Conflict - If it has not failed.
    • discard

      public BulkResult discard(RestRequest req, @Content BulkRequest body, @Query("fail") String fail)
      Discards changes in one aggregate call. The same key gets the same answer.
      Parameters:
      req - The request.
      body - {ids, idempotencyKey}.
      fail - discard to simulate a transport failure (demo toggle).
      Returns:
      The per-id outcome.
      Throws:
      BadRequest - If the key or the ids are missing.
      ServiceUnavailable - On ?fail=discard.