/** * Find the image's primary pixels object and, if an FS image, open a Bio-Formats reader for it. * @throws Cancel if there are no pixels for the image * @throws FormatException if the pixels service could not open a Bio-Formats reader for the image * @throws IOException if the pixels service could not open a Bio-Formats reader for the image */ private void findPixels() throws Cancel, FormatException, IOException { final String hql = "FROM Image WHERE id = :id"; final Query query = session.createQuery(hql).setParameter("id", imageId); final Image image = (Image) query.uniqueResult(); if (image.sizeOfPixels() < 1) { final Exception e = new IllegalArgumentException("no pixels for image " + imageId); throw helper.cancel(new ERR(), e, "bad-image"); } final Pixels pixels = image.getPrimaryPixels(); pixelsId = pixels.getId(); if (filesetId != null) { reader = pixelsService.getBfReader(pixels); } }
/** * Searches for a {@link Fileset} attached to this {@link Image}, and if present, * uses Bio-Formats to parse the metadata into the {@link OriginalMetadataResponse} * instance. If no {@link Fileset} is present, then there <em>may</em> be a * {@link FileAnnotation} present which has a static version of the metadata. */ protected void loadFileset() { rsp.filesetId = firstIdOrNull("select i.fileset.id from Image i where i.id = :id"); if (rsp.filesetId != null) { final Image image = helper.getServiceFactory().getQueryService().get(Image.class, imageId); final Pixels pixels = image.getPrimaryPixels(); try { final IFormatReader reader = pixelsService.getBfReader(pixels); final Hashtable<String, Object> global = reader.getGlobalMetadata(); final Hashtable<String, Object> series = reader.getSeriesMetadata(); rsp.globalMetadata = wrap(global); rsp.seriesMetadata = wrap(series); } catch (Throwable t) { helper.cancel(new ERR(), t, "bf-reader-failure", "pixels", ""+pixels.getId()); } } }