From 95b091707d32435465cd8ddf04d4e6d489a21a44 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 17 Nov 2016 17:46:20 -0500 Subject: [PATCH] Hatch printer-options command Returns available printer options for supported printer attributes for the provided printer (by name) or the default printer if none is specified. Signed-off-by: Bill Erickson --- src/org/evergreen_ils/hatch/PrintManager.java | 70 +++++++++++++++++++++++++ src/org/evergreen_ils/hatch/RequestHandler.java | 23 +++++++- src/org/evergreen_ils/hatch/TestHatch.java | 9 ++++ 3 files changed, 100 insertions(+), 2 deletions(-) diff --git a/src/org/evergreen_ils/hatch/PrintManager.java b/src/org/evergreen_ils/hatch/PrintManager.java index 841ebd4cdd..b0afe855fd 100644 --- a/src/org/evergreen_ils/hatch/PrintManager.java +++ b/src/org/evergreen_ils/hatch/PrintManager.java @@ -325,5 +325,75 @@ public class PrintManager { } } + public JSONObject getPrintersOptions(String printerName) { + Printer printer; + + if (printerName == null) { // no name provided, use default. + printer = Printer.getDefaultPrinter(); + } else { + printer = getPrinterByName(printerName); + } + + if (printer == null) return null; + + JSONObject options = new JSONObject(); + + PrinterAttributes printerAttrs = printer.getPrinterAttributes(); + + Set papers = printerAttrs.getSupportedPapers(); + JSONArray papersArray = new JSONArray(); + for (Paper source : papers) { + papersArray.put(source.getName()); + } + options.put("paper", papersArray); + + Set paperSources = + printerAttrs.getSupportedPaperSources(); + JSONArray paperSourcesArray = new JSONArray(); + for (PaperSource source : paperSources) { + paperSourcesArray.put(source.getName()); + } + options.put("paperSource", papersArray); + + + Set collations = printerAttrs.getSupportedCollations(); + JSONArray collationsArray = new JSONArray(); + for (Collation collation : collations) { + collationsArray.put(collation.toString()); + } + options.put("collation", collationsArray); + + Set colors = printerAttrs.getSupportedPrintColors(); + JSONArray colorsArray = new JSONArray(); + for (PrintColor color : colors) { + colorsArray.put(color.toString()); + } + options.put("printColor", colorsArray); + + Set qualities = printerAttrs.getSupportedPrintQuality(); + JSONArray qualityArray = new JSONArray(); + for (PrintQuality quality : qualities) { + qualityArray.put(quality.toString()); + } + options.put("printQuality", qualityArray); + + Set sides = printerAttrs.getSupportedPrintSides(); + JSONArray sidesArray = new JSONArray(); + for (PrintSides side : sides) { + sidesArray.put(side.toString()); + } + options.put("printSides", qualityArray); + + Set orients = + printerAttrs.getSupportedPageOrientations(); + JSONArray orientsArray = new JSONArray(); + for (PageOrientation orient : orients) { + orientsArray.put(orient.toString()); + } + options.put("pageOrientation", orientsArray); + + return options; + } + } diff --git a/src/org/evergreen_ils/hatch/RequestHandler.java b/src/org/evergreen_ils/hatch/RequestHandler.java index d4c0441c5d..e290c9e145 100644 --- a/src/org/evergreen_ils/hatch/RequestHandler.java +++ b/src/org/evergreen_ils/hatch/RequestHandler.java @@ -88,6 +88,25 @@ public class RequestHandler extends Thread { new PrintManager().getPrintersAsMaps()); break; + case "printer-options": + + String printer = request.optString("printer", null); + JSONObject options = + new PrintManager().getPrintersOptions(printer); + + if (options == null) { + response.put("status", 400); + if (printer == null) { + response.put("message", "No default printer found"); + } else { + response.put("message", "No such printer: " + printer); + } + } else { + response.put("content", options); + } + + break; + case "print": // Confirm a minimal data set to enqueue print requests. content = request.getString("content"); @@ -105,8 +124,8 @@ public class RequestHandler extends Thread { } case "keys": // Return stored keys - String pfxKey = request.optString("key"); - response.put("content", fileIO.keys(pfxKey)); + key = request.optString("key"); + response.put("content", fileIO.keys(key)); break; case "get": diff --git a/src/org/evergreen_ils/hatch/TestHatch.java b/src/org/evergreen_ils/hatch/TestHatch.java index 616c188e2d..96624affa4 100644 --- a/src/org/evergreen_ils/hatch/TestHatch.java +++ b/src/org/evergreen_ils/hatch/TestHatch.java @@ -110,6 +110,15 @@ public class TestHatch { pause(); + // get a list of printers + obj = new JSONObject(); + obj.put("msgid", msgid++); + obj.put("clientid", clientid); + obj.put("action", "printer-options"); + io.sendMessage(obj); + + pause(); + /* // Printing tests -- 2.11.0