Hatch printer-options command
authorBill Erickson <berickxx@gmail.com>
Thu, 17 Nov 2016 22:46:20 +0000 (17:46 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 17 Nov 2016 22:46:25 +0000 (17:46 -0500)
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 <berickxx@gmail.com>
src/org/evergreen_ils/hatch/PrintManager.java
src/org/evergreen_ils/hatch/RequestHandler.java
src/org/evergreen_ils/hatch/TestHatch.java

index 841ebd4..b0afe85 100644 (file)
@@ -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<Paper> papers = printerAttrs.getSupportedPapers();
+        JSONArray papersArray = new JSONArray();
+        for (Paper source : papers) {
+            papersArray.put(source.getName());
+        }
+        options.put("paper", papersArray);
+
+        Set<PaperSource> paperSources = 
+            printerAttrs.getSupportedPaperSources();
+        JSONArray paperSourcesArray = new JSONArray();
+        for (PaperSource source : paperSources) {
+            paperSourcesArray.put(source.getName());
+        }
+        options.put("paperSource", papersArray);
+
+
+        Set<Collation> collations = printerAttrs.getSupportedCollations();
+        JSONArray collationsArray = new JSONArray();
+        for (Collation collation : collations) {
+            collationsArray.put(collation.toString());
+        }
+        options.put("collation", collationsArray);
+
+        Set<PrintColor> colors = printerAttrs.getSupportedPrintColors();
+        JSONArray colorsArray = new JSONArray();
+        for (PrintColor color : colors) {
+            colorsArray.put(color.toString());
+        }
+        options.put("printColor", colorsArray);
+
+        Set<PrintQuality> qualities = printerAttrs.getSupportedPrintQuality();
+        JSONArray qualityArray = new JSONArray();
+        for (PrintQuality quality : qualities) {
+            qualityArray.put(quality.toString());
+        }
+        options.put("printQuality", qualityArray);
+
+        Set<PrintSides> sides = printerAttrs.getSupportedPrintSides();
+        JSONArray sidesArray = new JSONArray();
+        for (PrintSides side : sides) {
+            sidesArray.put(side.toString());
+        }
+        options.put("printSides", qualityArray);
+
+        Set<PageOrientation> orients = 
+            printerAttrs.getSupportedPageOrientations();
+        JSONArray orientsArray = new JSONArray();
+        for (PageOrientation orient : orients) {
+            orientsArray.put(orient.toString());
+        }
+        options.put("pageOrientation", orientsArray);
+
+        return options;
+    }
+
 }
 
index d4c0441..e290c9e 100644 (file)
@@ -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":
index 616c188..96624af 100644 (file)
@@ -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