예제 #1
0
 private final String getNetworkViewString(final CyNetworkView networkView) {
   final ByteArrayOutputStream stream = new ByteArrayOutputStream();
   CyWriter writer = cytoscapeJsWriterFactory.createWriter(stream, networkView);
   String jsonString = null;
   try {
     writer.run(null);
     jsonString = stream.toString("UTF-8");
     stream.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return jsonString;
 }
예제 #2
0
  protected final String getNetworkString(final CyNetwork network) {
    final ByteArrayOutputStream stream = new ByteArrayOutputStream();
    CyWriter writer = cytoscapeJsWriterFactory.createWriter(stream, network);
    String jsonString = null;
    try {
      writer.run(new HeadlessTaskMonitor());
      jsonString = stream.toString("UTF-8");
      stream.close();
    } catch (Exception e) {
      throw getError(
          "Could not serialize network into JSON.", e, Response.Status.PRECONDITION_FAILED);
    }

    return jsonString;
  }
예제 #3
0
  private final Response imageGenerator(
      final String fileType,
      PresentationWriterFactory factory,
      final CyNetworkView view,
      int width,
      int height) {
    final Collection<RenderingEngine<?>> re = renderingEngineManager.getRenderingEngines(view);
    if (re.isEmpty()) {
      throw new IllegalArgumentException("No rendering engine.");
    }
    try {
      RenderingEngine<?> engine = null;

      for (RenderingEngine<?> r : re) {
        if (r.getRendererId().equals(DING_ID)) {
          engine = r;
          break;
        }
      }
      if (engine == null) {
        throw new IllegalArgumentException("Could not find Ding rendering eigine.");
      }

      final ByteArrayOutputStream baos = new ByteArrayOutputStream();

      final CyWriter writer = factory.createWriter(baos, engine);

      if (fileType.equals("png")) {
        // Do some hack to set properties...
        // TODO: Are there cleaner way to access these props?
        final Object zl = writer.getClass().getMethod("getZoom").invoke(writer);
        final BoundedDouble bound = (BoundedDouble) zl;
        // System.out.println("UB = " + bound.getUpperBound());
        // System.out.println("LB = " + bound.getLowerBound());

        // Set large upper bound for generating large PNG.
        bound.setBounds(bound.getLowerBound(), 5000.0);
        writer.getClass().getMethod("setHeightInPixels", int.class).invoke(writer, height);
      }
      writer.run(new HeadlessTaskMonitor());

      final byte[] imageData = baos.toByteArray();
      return Response.ok(new ByteArrayInputStream(imageData)).build();
    } catch (Exception e) {
      e.printStackTrace();
      throw getError("Could not create image.", e, Response.Status.INTERNAL_SERVER_ERROR);
    }
  }
예제 #4
0
  private final String getNetworkViewsAsCX(final CyRootNetwork root) {
    final CyNetworkViewWriterFactory cxWriterFactory =
        viewWriterFactoryManager.getFactory(CyNetworkViewWriterFactoryManager.CX_WRITER_ID);

    final ByteArrayOutputStream stream = new ByteArrayOutputStream();
    CyWriter writer = cxWriterFactory.createWriter(stream, root.getSubNetworkList().get(0));
    String jsonString = null;
    try {
      writer.run(null);
      jsonString = stream.toString("UTF-8");
      stream.close();
    } catch (Exception e) {
      throw getError(
          "Failed to serialize network into CX: " + root, e, Response.Status.INTERNAL_SERVER_ERROR);
    }
    return jsonString;
  }