Record Class PrinterHealthReport

java.lang.Object
java.lang.Record
io.github.chkrishnatej.rp3200.health.PrinterHealthReport
Record Components:
event - "health" (regular check) or "print-failed"
reachable - false when the browser could not reach the agent at all (not installed, not running, or blocked by the browser)
errorCode - AGENT_UNREACHABLE, AGENT_ERROR or SERVER_ERROR; null if none
errorMessage - the error shown to the user, or null
agent - the agent's status, or null when it was unreachable
page - the page that sent the report (origin + path)
userAgent - the browser's user agent string
reportedAt - when the browser created the report

public record PrinterHealthReport(String event, boolean reachable, String errorCode, String errorMessage, AgentStatus agent, String page, String userAgent, Instant reportedAt) extends Record
A health report posted by rp3200-print.js to your server, so you can see the state of every shop's printer without remote access to the PC.

The browser sends one when checkHealth() is called (e.g. on page load or every few minutes via startHealthReporting()), and automatically after a failed print - provided the page created the helper with new RP3200Printer({ reportUrl: '/api/printer-health' }). Because the request comes from the logged-in page (same-origin cookies), your server knows which shop/user sent it.


 @PostMapping("/api/printer-health")
 void report(@RequestBody PrinterHealthReport report, @AuthenticationPrincipal ShopUser user) {
     healthStore.put(user.shopId(), report);              // keep the latest per shop
     if (!report.healthy()) log.warn("Printer problem at {}: {}", user.shopId(), report.problem());
 }
 
  • Constructor Details

    • PrinterHealthReport

      public PrinterHealthReport(String event, boolean reachable, String errorCode, String errorMessage, AgentStatus agent, String page, String userAgent, Instant reportedAt)
      Creates an instance of a PrinterHealthReport record class.
      Parameters:
      event - the value for the event record component
      reachable - the value for the reachable record component
      errorCode - the value for the errorCode record component
      errorMessage - the value for the errorMessage record component
      agent - the value for the agent record component
      page - the value for the page record component
      userAgent - the value for the userAgent record component
      reportedAt - the value for the reportedAt record component
  • Method Details

    • healthy

      public boolean healthy()
      Returns whether printing should work: the agent answered, its printer is ready and the report is not about a failed print.
      Returns:
      true if everything is fine
    • problem

      public String problem()
      Returns a one-line description of the problem, for logs and admin pages.
      Returns:
      the problem, or "ok" when healthy()
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • event

      public String event()
      Returns the value of the event record component.
      Returns:
      the value of the event record component
    • reachable

      public boolean reachable()
      Returns the value of the reachable record component.
      Returns:
      the value of the reachable record component
    • errorCode

      public String errorCode()
      Returns the value of the errorCode record component.
      Returns:
      the value of the errorCode record component
    • errorMessage

      public String errorMessage()
      Returns the value of the errorMessage record component.
      Returns:
      the value of the errorMessage record component
    • agent

      public AgentStatus agent()
      Returns the value of the agent record component.
      Returns:
      the value of the agent record component
    • page

      public String page()
      Returns the value of the page record component.
      Returns:
      the value of the page record component
    • userAgent

      public String userAgent()
      Returns the value of the userAgent record component.
      Returns:
      the value of the userAgent record component
    • reportedAt

      public Instant reportedAt()
      Returns the value of the reportedAt record component.
      Returns:
      the value of the reportedAt record component