Class FavoritePostHandler

java.lang.Object
org.codelibs.fess.api.v2.handlers.FavoritePostHandler

public class FavoritePostHandler extends Object
Handles POST /api/v2/documents/{docId}/favorite.

Marks a document as a favorite for the calling user and bumps the document's favorite counter. Mirrors v1's SearchApiManager#processFavoriteRequest but with the v2 envelope and a JSON body (the query_id that v1 read from a query parameter now lives in the request body).

Order of checks:

  1. HTTP method must be POST.
  2. docId must be non-blank and match [A-Za-z0-9_-]+.
  3. Caller must be authenticated (saved FessUserBean present) — the login lookup is wrapped in try/catch so unit harnesses without DBFlute behaviors are treated as anonymous (consistent with MeHandler).
  4. user.favorite feature flag must be enabled.
  5. Body must parse and contain query_id.
  6. The docId must appear in the user's last result set.
  7. The document must exist in the index.

The ifPresent / orElse(Runnable) shape and the exception-as- control-flow inside the lambda are kept verbatim from v1 so reviewers can diff the two paths side-by-side. The outer try/catch converts any lambda-thrown RuntimeException into a structured v2 error envelope rather than letting it bubble up as a 500 HTML page.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor used by the DI container.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    handle(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, String docId)
    Processes one POST /api/v2/documents/{docId}/favorite request.

    Methods inherited from class java.lang.Object

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

    • FavoritePostHandler

      public FavoritePostHandler()
      Default constructor used by the DI container. The handler holds no per-request state and is safe to share across concurrent requests.
  • Method Details

    • handle

      public void handle(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, String docId) throws IOException
      Processes one POST /api/v2/documents/{docId}/favorite request.

      Validates the HTTP method, document id format, authenticated session, favorite feature flag and request body. On success a favorite is recorded for the user and a success envelope is returned. Failures map to v2 error codes (V2ErrorCode.AUTH_REQUIRED, V2ErrorCode.INVALID_REQUEST, V2ErrorCode.NOT_FOUND, V2ErrorCode.INTERNAL_ERROR).

      Parameters:
      req - the incoming HTTP request
      res - the HTTP response to write to
      docId - the document id extracted from the URL path
      Throws:
      IOException - if writing the envelope or reading the body fails