예제 #1
0
  /**
   * To use this API, you need to know SUID of the CyNetworkView, in addition to CyNetwork SUID.
   *
   * @summary Get a network view (as JSON or a file)
   * @param networkId Network SUID
   * @param viewId Network View SUID
   * @param file (Optional) If you want to get the view as a file, you can specify output file name
   *     with extension. For example, file=test.sif creates new SIF file in the current directory.
   * @return View in Cytoscape.js JSON. Currently, view information is (x, y) location only. If you
   *     specify <strong>file</strong> option, this returns absolute path to the file.
   */
  @GET
  @Path("/{viewId}")
  @Produces(MediaType.APPLICATION_JSON)
  public Response getNetworkView(
      @PathParam("networkId") Long networkId,
      @PathParam("viewId") Long viewId,
      @QueryParam("file") String file) {
    final Collection<CyNetworkView> views = this.getCyNetworkViews(networkId);

    CyNetworkView targetView = null;
    for (final CyNetworkView view : views) {
      final Long vid = view.getSUID();
      if (vid.equals(viewId)) {
        targetView = view;
        break;
      }
    }

    if (targetView == null) {
      return Response.ok("{}").build();
    } else {
      if (file != null) {
        return Response.ok(writeNetworkFile(file, targetView)).build();
      } else {
        return Response.ok(getNetworkViewString(targetView)).build();
      }
    }
  }
예제 #2
0
 private final CyNetworkView getView(Long networkId, Long viewId) {
   final Collection<CyNetworkView> views = this.getCyNetworkViews(networkId);
   for (final CyNetworkView view : views) {
     final Long vid = view.getSUID();
     if (vid.equals(viewId)) {
       return view;
     }
   }
   throw new NotFoundException("Could not find view: " + viewId);
 }
예제 #3
0
  private Response getImageForView(String fileType, Long networkId, Long viewId, Integer height) {
    final Collection<CyNetworkView> views = this.getCyNetworkViews(networkId);
    for (final CyNetworkView view : views) {
      final Long vid = view.getSUID();
      if (vid.equals(viewId)) {
        return getImage(fileType, networkId, height);
      }
    }

    throw new NotFoundException("Could not find view for the network: " + networkId);
  }
예제 #4
0
 /**
  * @summary Create view for the network
  * @param networkId Network SUID
  * @return SUID for the new Network View.
  */
 @POST
 @Path("/")
 @Produces(MediaType.APPLICATION_JSON)
 public Response createNetworkView(@PathParam("networkId") Long networkId) {
   final CyNetwork network = getCyNetwork(networkId);
   final CyNetworkView view = networkViewFactory.createNetworkView(network);
   networkViewManager.addNetworkView(view);
   return Response.status(Response.Status.CREATED)
       .entity(getNumberObjectString("networkViewSUID", view.getSUID()))
       .build();
 }
예제 #5
0
 /**
  * This returns the first view of the network. As of Cytoscape 3.2.x, this is the only view
  * accessible Cytoscape GUI.
  *
  * @summary Convenience method to get the first view model.
  * @param networkId Network SUID
  * @param file (Optional) If you want to get the view as a file, you can specify output file name
  *     with extension. For example, file=test.sif creates new SIF file in the current directory.
  * @return Network view in JSON or location of the file
  */
 @GET
 @Path("/first")
 @Produces(MediaType.APPLICATION_JSON)
 public Response getFirstNetworkView(
     @PathParam("networkId") Long networkId, @QueryParam("file") String file) {
   final Collection<CyNetworkView> views = this.getCyNetworkViews(networkId);
   if (views.isEmpty()) {
     throw new NotFoundException("Could not find view for the network: " + networkId);
   }
   final CyNetworkView view = views.iterator().next();
   return getNetworkView(networkId, view.getSUID(), file);
 }
예제 #6
0
  /**
   * @summary Get SUID of all network views
   * @param networkId Network SUID
   * @return Array of all network view SUIDs
   */
  @GET
  @Path("/")
  @Produces(MediaType.APPLICATION_JSON)
  public Collection<Long> getAllNetworkViews(@PathParam("networkId") Long networkId) {
    final Collection<CyNetworkView> views = this.getCyNetworkViews(networkId);

    final Collection<Long> suids = new HashSet<Long>();

    for (final CyNetworkView view : views) {
      final Long viewId = view.getSUID();
      suids.add(viewId);
    }
    return suids;
  }