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-falsewhen the browser could not reach the agent at all (not installed, not running, or blocked by the browser)errorCode-AGENT_UNREACHABLE,AGENT_ERRORorSERVER_ERROR; null if noneerrorMessage- the error shown to the user, or nullagent- the agent's status, or null when it was unreachablepage- the page that sent the report (origin + path)userAgent- the browser's user agent stringreportedAt- 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 Summary
ConstructorsConstructorDescriptionPrinterHealthReport(String event, boolean reachable, String errorCode, String errorMessage, AgentStatus agent, String page, String userAgent, Instant reportedAt) Creates an instance of aPrinterHealthReportrecord class. -
Method Summary
Modifier and TypeMethodDescriptionagent()Returns the value of theagentrecord component.final booleanIndicates whether some other object is "equal to" this one.Returns the value of theerrorCoderecord component.Returns the value of theerrorMessagerecord component.event()Returns the value of theeventrecord component.final inthashCode()Returns a hash code value for this object.booleanhealthy()Returns whether printing should work: the agent answered, its printer is ready and the report is not about a failed print.page()Returns the value of thepagerecord component.problem()Returns a one-line description of the problem, for logs and admin pages.booleanReturns the value of thereachablerecord component.Returns the value of thereportedAtrecord component.final StringtoString()Returns a string representation of this record class.Returns the value of theuserAgentrecord component.
-
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 aPrinterHealthReportrecord class.- Parameters:
event- the value for theeventrecord componentreachable- the value for thereachablerecord componenterrorCode- the value for theerrorCoderecord componenterrorMessage- the value for theerrorMessagerecord componentagent- the value for theagentrecord componentpage- the value for thepagerecord componentuserAgent- the value for theuserAgentrecord componentreportedAt- the value for thereportedAtrecord 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:
trueif everything is fine
-
problem
Returns a one-line description of the problem, for logs and admin pages.- Returns:
- the problem, or
"ok"whenhealthy()
-
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
event
Returns the value of theeventrecord component.- Returns:
- the value of the
eventrecord component
-
reachable
public boolean reachable()Returns the value of thereachablerecord component.- Returns:
- the value of the
reachablerecord component
-
errorCode
Returns the value of theerrorCoderecord component.- Returns:
- the value of the
errorCoderecord component
-
errorMessage
Returns the value of theerrorMessagerecord component.- Returns:
- the value of the
errorMessagerecord component
-
agent
Returns the value of theagentrecord component.- Returns:
- the value of the
agentrecord component
-
page
Returns the value of thepagerecord component.- Returns:
- the value of the
pagerecord component
-
userAgent
Returns the value of theuserAgentrecord component.- Returns:
- the value of the
userAgentrecord component
-
reportedAt
Returns the value of thereportedAtrecord component.- Returns:
- the value of the
reportedAtrecord component
-