public void parseStatsMessage(Message<Map<String, Map<String, byte[]>>> message) throws IOException { Map<String, Map<String, byte[]>> a = message.getPayload(); for (String type : a.keySet()) { Map<String, byte[]> b = a.get(type); for (String filename : b.keySet()) { log.info("Processing stats for: " + filename); BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(b.get(filename))); File outFile = null; OutputStream out = null; try { outFile = new File(new File("/tmp/"), filename); try { out = new FileOutputStream(outFile); byte[] buf = new byte[16884]; int len; while ((len = bis.read(buf)) > 0) { out.write(buf, 0, len); } } catch (IOException e) { log.error("Could not write temporary file: " + outFile.getAbsolutePath()); e.printStackTrace(); } finally { try { bis.close(); } catch (IOException e) { // ignore } } } finally { if (out != null) { out.close(); } if (outFile != null) { File newFile = misoFileManager.storeFile(Run.class, "stats", outFile); if (newFile != null && outFile.delete()) { File destination = new File(newFile.getParentFile(), newFile.getName().split("-")[0]); if (LimsUtils.checkDirectory(destination, true)) { if (LimsUtils.unzipFile(newFile, destination)) { newFile.delete(); } } } } } } } }
public JSONObject getPlateBarcode(HttpSession session, JSONObject json) { Long plateId = json.getLong("plateId"); File temploc = new File(session.getServletContext().getRealPath("/") + "temp/"); try { // Plate<LinkedList<Plateable>, Plateable> plate = requestManager.<LinkedList<Plateable>, // Plateable> getPlateById(plateId); Plate<? extends List<? extends Plateable>, ? extends Plateable> plate = requestManager.getPlateById(plateId); barcodeFactory.setPointPixels(1.5f); barcodeFactory.setBitmapResolution(600); RenderedImage bi = null; if (json.has("barcodeGenerator")) { BarcodeDimension dim = new BarcodeDimension(100, 100); if (json.has("dimensionWidth") && json.has("dimensionHeight")) { dim = new BarcodeDimension( json.getDouble("dimensionWidth"), json.getDouble("dimensionHeight")); } BarcodeGenerator bg = BarcodeFactory.lookupGenerator(json.getString("barcodeGenerator")); if (bg != null) { bi = barcodeFactory.generateBarcode(plate, bg, dim); } else { return JSONUtils.SimpleJSONError( "'" + json.getString("barcodeGenerator") + "' is not a valid barcode generator type"); } } else { bi = barcodeFactory.generateSquareDataMatrix(plate, 400); } if (bi != null) { File tempimage = misoFileManager.generateTemporaryFile("barcode-", ".png", temploc); if (ImageIO.write(bi, "png", tempimage)) { return JSONUtils.JSONObjectResponse("img", tempimage.getName()); } return JSONUtils.SimpleJSONError("Writing temp image file failed."); } else { return JSONUtils.SimpleJSONError("Plate has no parseable barcode"); } } catch (IOException e) { e.printStackTrace(); return JSONUtils.SimpleJSONError( e.getMessage() + ": Cannot seem to access " + temploc.getAbsolutePath()); } }
public JSONObject downloadPlateInputForm(HttpSession session, JSONObject json) { if (json.has("documentFormat")) { String documentFormat = json.getString("documentFormat"); try { File f = misoFileManager.getNewFile( Plate.class, "forms", "PlateInputForm-" + LimsUtils.getCurrentDateAsString() + "." + documentFormat); FormUtils.createPlateInputSpreadsheet(f); return JSONUtils.SimpleJSONResponse("" + f.getName().hashCode()); } catch (Exception e) { e.printStackTrace(); return JSONUtils.SimpleJSONError("Failed to get plate input form: " + e.getMessage()); } } else { return JSONUtils.SimpleJSONError("Missing project ID or document format supplied."); } }