Ejemplo n.º 1
0
  @GET
  @Path("/{viewId}/{objectType}/{objectId}/{visualProperty}")
  @Produces(MediaType.APPLICATION_JSON)
  public String getSingleVisualPropertyValue(
      @PathParam("networkId") Long networkId,
      @PathParam("viewId") Long viewId,
      @PathParam("objectType") String objectType,
      @PathParam("objectId") Long objectId,
      @PathParam("visualProperty") String visualProperty) {
    final CyNetworkView networkView = getView(networkId, viewId);

    Collection<VisualProperty<?>> vps = null;
    View<? extends CyIdentifiable> view = null;
    if (nodeLexicon == null) {
      initLexicon();
    }

    if (objectType.equals("nodes")) {
      view = networkView.getNodeView(networkView.getModel().getNode(objectId));
      vps = nodeLexicon;
    } else if (objectType.equals("edges")) {
      view = networkView.getNodeView(networkView.getModel().getNode(objectId));
      vps = edgeLexicon;
    }

    if (view == null) {
      throw getError(
          "Could not find view.", new IllegalArgumentException(), Response.Status.NOT_FOUND);
    }

    return getSingleVp(visualProperty, view, vps);
  }
  private void checkView(final CyNetworkView view) {
    assertEquals(Color.BLACK, view.getVisualProperty(NETWORK_BACKGROUND_PAINT));
    assertEquals(new Double(639.0d), view.getVisualProperty(NETWORK_WIDTH));
    assertEquals(new Double(624.0d), view.getVisualProperty(NETWORK_HEIGHT));
    assertEquals(
        new Double(3091.2991395970175d), view.getVisualProperty(NETWORK_CENTER_X_LOCATION));
    assertEquals(new Double(3610.396738076269d), view.getVisualProperty(NETWORK_CENTER_Y_LOCATION));
    assertEquals(new Double(0.05044042295795177d), view.getVisualProperty(NETWORK_SCALE_FACTOR));

    // All nodes have the same size, border and shape
    final View<CyNode> nv = view.getNodeView(view.getModel().getNodeList().iterator().next());
    assertEquals(80, nv.getVisualProperty(NODE_WIDTH).intValue());
    assertEquals(30, nv.getVisualProperty(NODE_HEIGHT).intValue());
    assertEquals(NodeShapeVisualProperty.ROUND_RECTANGLE, nv.getVisualProperty(NODE_SHAPE));
    assertEquals(180, nv.getVisualProperty(NODE_TRANSPARENCY).intValue());
    assertEquals(2, nv.getVisualProperty(NODE_BORDER_WIDTH).intValue());
    assertEquals(LineTypeVisualProperty.SOLID, nv.getVisualProperty(NODE_BORDER_LINE_TYPE));
    assertEquals(new Color(153, 153, 255), nv.getVisualProperty(NODE_BORDER_PAINT));
    assertEquals(255, nv.getVisualProperty(NODE_BORDER_TRANSPARENCY).intValue());
    assertEquals(new Color(255, 255, 255), nv.getVisualProperty(NODE_LABEL_COLOR));
    assertEquals(255, nv.getVisualProperty(NODE_LABEL_TRANSPARENCY).intValue());

    // All edges have the same width and other properties
    final View<CyEdge> ev = view.getEdgeView(view.getModel().getEdgeList().iterator().next());
    assertEquals(new Double(1.0), ev.getVisualProperty(EDGE_WIDTH));
    assertEquals(255, ev.getVisualProperty(EDGE_TRANSPARENCY).intValue());
    assertEquals(ArrowShapeVisualProperty.NONE, ev.getVisualProperty(EDGE_SOURCE_ARROW_SHAPE));
    assertEquals(ArrowShapeVisualProperty.NONE, ev.getVisualProperty(EDGE_TARGET_ARROW_SHAPE));
  }
Ejemplo n.º 3
0
  /**
   * By passing list of key-value pair for each Visual Property, update node view.
   *
   * <p>The body should have the following JSON:
   *
   * <pre>
   * [
   * 		{
   * 			"SUID": SUID of node,
   * 			"view": [
   * 				{
   * 					"visualProperty": "Visual Property Name, like NODE_FILL_COLOR",
   * 					"value": "Serialized form of value, like 'red.'"
   * 				},
   * 				...
   * 				{}
   * 			]
   * 		},
   * 		...
   * 		{}
   * ]
   * </pre>
   *
   * Note that this API directly set the value to the view objects, and once Visual Style applied,
   * those values are overridden by the Visual Style.
   *
   * @summary Update node/edge view objects at once
   * @param networkId Network SUID
   * @param viewId Network view SUID
   * @param objectType Type of objects ("nodes" or "edges")
   */
  @PUT
  @Path("/{viewId}/{objectType}")
  @Consumes(MediaType.APPLICATION_JSON)
  public Response updateViews(
      @PathParam("networkId") Long networkId,
      @PathParam("viewId") Long viewId,
      @PathParam("objectType") String objectType,
      final InputStream is) {

    final CyNetworkView networkView = getView(networkId, viewId);

    final ObjectMapper objMapper = new ObjectMapper();

    try {
      // This should be an JSON array.
      final JsonNode rootNode = objMapper.readValue(is, JsonNode.class);

      for (JsonNode entry : rootNode) {
        final Long objectId = entry.get(CyIdentifiable.SUID).asLong();
        final JsonNode viewNode = entry.get("view");
        if (objectId == null || viewNode == null) {
          continue;
        }

        View<? extends CyIdentifiable> view = null;
        if (objectType.equals("nodes")) {
          view = networkView.getNodeView(networkView.getModel().getNode(objectId));
        } else if (objectType.equals("edges")) {
          view = networkView.getEdgeView(networkView.getModel().getEdge(objectId));
        } else if (objectType.equals("network")) {
          view = networkView;
        } else {
          throw getError(
              "Method not supported.",
              new IllegalStateException(),
              Response.Status.INTERNAL_SERVER_ERROR);
        }

        if (view == null) {
          throw getError(
              "Could not find view.", new IllegalArgumentException(), Response.Status.NOT_FOUND);
        }
        styleMapper.updateView(view, viewNode, getLexicon());
      }

      // Repaint
      networkView.updateView();
    } catch (Exception e) {
      throw getError(
          "Could not parse the input JSON for updating view because: " + e.getMessage(),
          e,
          Response.Status.INTERNAL_SERVER_ERROR);
    }
    return Response.ok().build();
  }
Ejemplo n.º 4
0
  /**
   * @summary Get view object for the specified type (node or edge)
   * @param networkId Network SUID
   * @param viewId Network view SUID
   * @param objectType nodes or edges
   * @param objectId Object's SUID
   */
  @GET
  @Path("/{viewId}/{objectType}/{objectId}")
  @Produces(MediaType.APPLICATION_JSON)
  public String getView(
      @PathParam("networkId") Long networkId,
      @PathParam("viewId") Long viewId,
      @PathParam("objectType") String objectType,
      @PathParam("objectId") Long objectId) {
    final CyNetworkView networkView = getView(networkId, viewId);

    View<? extends CyIdentifiable> view = null;
    Collection<VisualProperty<?>> lexicon = null;
    if (nodeLexicon == null) {
      initLexicon();
    }

    if (objectType.equals("nodes")) {
      view = networkView.getNodeView(networkView.getModel().getNode(objectId));
      lexicon = nodeLexicon;
    } else if (objectType.equals("edges")) {
      view = networkView.getNodeView(networkView.getModel().getNode(objectId));
      lexicon = edgeLexicon;
    }

    if (view == null) {
      throw getError(
          "Could not find view.", new IllegalArgumentException(), Response.Status.NOT_FOUND);
    }

    try {
      return styleSerializer.serializeView(view, lexicon);
    } catch (IOException e) {
      throw getError(
          "Could not serialize the view object.", e, Response.Status.INTERNAL_SERVER_ERROR);
    }
  }
  @Override
  public void run(final TaskMonitor taskMonitor) {
    if (network == null) network = appMgr.getCurrentNetwork();
    Collection<CyNetworkView> views = viewMgr.getNetworkViews(network);

    nodes = nodeList.getValue();

    for (CyNetworkView view : views) {
      Set<View<CyNode>> nodeViews = new HashSet<View<CyNode>>();
      if (nodes == null || nodes.size() == 0) {
        nodeViews = CyLayoutAlgorithm.ALL_NODE_VIEWS;
      } else {
        for (CyNode node : nodes) nodeViews.add(view.getNodeView(node));
      }

      insertTasksAfterCurrentTask(
          algorithm.createTaskIterator(view, layoutContext, nodeViews, getLayoutAttribute()));
    }
  }
  @Override
  public void serialize(CyNetworkView networkView, JsonGenerator jgen, SerializerProvider provider)
      throws IOException, JsonProcessingException {
    jgen.useDefaultPrettyPrinter();

    jgen.writeStartObject();
    jgen.writeStringField(
        CytoscapeJsNetworkModule.FORMAT_VERSION_TAG, CytoscapeJsNetworkModule.FORMAT_VERSION);
    jgen.writeStringField(CytoscapeJsNetworkModule.GENERATED_BY_TAG, "cytoscape-" + version);
    jgen.writeStringField(
        CytoscapeJsNetworkModule.TARGET_CYJS_VERSION_TAG,
        CytoscapeJsNetworkModule.CYTOSCAPEJS_VERSION);

    final CyNetwork network = networkView.getModel();

    // Serialize network data table
    jgen.writeObjectFieldStart(DATA.getTag());
    jgen.writeObject(network.getRow(network));
    jgen.writeEndObject();

    jgen.writeObjectFieldStart(ELEMENTS.getTag());

    // Write array
    final List<CyNode> nodes = network.getNodeList();
    final List<CyEdge> edges = network.getEdgeList();

    jgen.writeArrayFieldStart(NODES.getTag());
    for (final CyNode node : nodes) {
      jgen.writeStartObject();

      // Data field
      jgen.writeObjectFieldStart(DATA.getTag());
      jgen.writeStringField(ID.getTag(), node.getSUID().toString());
      // Write CyRow in "data" field
      jgen.writeObject(network.getRow(node));
      jgen.writeEndObject();

      // Position and other visual props
      jgen.writeObject(networkView.getNodeView(node));

      // Special case for cytoscape.js format:
      // - Selected
      jgen.writeBooleanField(
          CyNetwork.SELECTED, network.getRow(node).get(CyNetwork.SELECTED, Boolean.class));

      jgen.writeEndObject();
    }
    jgen.writeEndArray();

    jgen.writeArrayFieldStart(EDGES.getTag());
    for (final CyEdge edge : edges) {
      jgen.writeStartObject();

      jgen.writeObjectFieldStart(DATA.getTag());
      jgen.writeStringField(ID.getTag(), edge.getSUID().toString());
      jgen.writeStringField(SOURCE.getTag(), edge.getSource().getSUID().toString());
      jgen.writeStringField(TARGET.getTag(), edge.getTarget().getSUID().toString());

      // Write CyRow in "data" field
      jgen.writeObject(network.getRow(edge));

      jgen.writeEndObject();

      // Special case for cytoscape.js format:
      // - Selected
      jgen.writeBooleanField(
          CyNetwork.SELECTED, network.getRow(edge).get(CyNetwork.SELECTED, Boolean.class));

      jgen.writeEndObject();
    }
    jgen.writeEndArray();

    jgen.writeEndObject();
  }