Exemplo n.º 1
0
  /** Return SUID of root networks */
  @GET
  @Path("/")
  @Produces(MediaType.APPLICATION_JSON + "; charset=UTF-8")
  public Collection<Long> getCollectionsAsSUID(@QueryParam("subsuid") Long subsuid) {
    if (subsuid == null) {
      // Return all collection SUIDs
      return getRootNetworks().stream().map(root -> root.getSUID()).collect(Collectors.toSet());
    } else {
      // Return parent collection's SUID
      final CyNetwork subnetwork = networkManager.getNetwork(subsuid);
      if (subnetwork == null) {
        throw new NotFoundException();
      }

      final CyRootNetwork root = cyRootNetworkManager.getRootNetwork(subnetwork);
      if (root == null) {
        throw new NotFoundException();
      } else {
        final List<Long> rootId = new ArrayList<>();
        rootId.add(root.getSUID());

        return rootId;
      }
    }
  }
Exemplo n.º 2
0
 private final CyRootNetwork getRootNetwork(final Long suid) {
   final Set<CyRootNetwork> roots = getRootNetworks();
   for (final CyRootNetwork root : roots) {
     if (root.getSUID().equals(suid)) {
       return root;
     }
   }
   return null;
 }
Exemplo n.º 3
0
 private final CyTable getTable(Long networkId, final String tableType) {
   final CyRootNetwork root = getRootNetwork(networkId);
   if (tableType.equals("default")) {
     return root.getDefaultNetworkTable();
   } else if (tableType.equals("shared")) {
     return root.getSharedNetworkTable();
   } else {
     return null;
   }
 }
Exemplo n.º 4
0
  @GET
  @Path("/{networkId}/subnetworks")
  @Produces(MediaType.APPLICATION_JSON)
  public Response getSubnetworks(@PathParam("networkId") Long networkId) {
    final CyRootNetwork root = getRootNetwork(networkId);
    final List<CySubNetwork> subnetworks = root.getSubNetworkList();
    final Set<Long> subnetIds =
        subnetworks.stream().map(subNet -> subNet.getSUID()).collect(Collectors.toSet());

    return getResponse(subnetIds);
  }
Exemplo n.º 5
0
  @GET
  @Path("/{networkId}/tables")
  @Produces(MediaType.APPLICATION_JSON)
  public Response getRootTables(@PathParam("networkId") Long networkId) {
    final CyRootNetwork root = getRootNetwork(networkId);
    final CyTable table = root.getDefaultNetworkTable();
    final CyTable shared = root.getSharedNetworkTable();
    final Set<CyTable> tables = new HashSet<>();
    tables.add(shared);
    tables.add(table);

    return getResponse(tables);
  }
  private static HashMap<String, CyRootNetwork> getRootNetworkMap(
      CyNetworkManager cyNetworkManager, CyRootNetworkManager cyRootNetworkManager) {

    HashMap<String, CyRootNetwork> name2RootMap = new HashMap<String, CyRootNetwork>();

    for (CyNetwork net : cyNetworkManager.getNetworkSet()) {
      final CyRootNetwork rootNet = cyRootNetworkManager.getRootNetwork(net);
      if (!name2RootMap.containsValue(rootNet))
        name2RootMap.put(rootNet.getRow(rootNet).get(CyRootNetwork.NAME, String.class), rootNet);
    }

    return name2RootMap;
  }
  private void extractNetworks(InputStream is, String entryName) throws Exception {
    CyNetworkReader reader = networkReaderMgr.getReader(is, entryName);
    reader.run(taskMonitor);
    final CyNetwork[] netArray = reader.getNetworks();

    for (final CyNetwork net : netArray) {
      // Add its root-network to the lookup map first
      final CyRootNetwork rootNet = rootNetworkManager.getRootNetwork(net);

      if (!networkLookup.containsKey(rootNet.getSUID())) ;
      networkLookup.put(rootNet.getSUID(), rootNet);

      networkLookup.put(net.getSUID(), net);
      networks.add(net); // Note: do NOT add the root-network to this set!
    }
  }
  // Build the key-node map for the entire root network
  // Note: The keyColName should start with "shared"
  private void initNodeMap() {

    String networkCollectionName = this.rootNetworkList.getSelectedValue().toString();
    CyRootNetwork rootNetwork = this.name2RootMap.get(networkCollectionName);

    if (networkCollectionName.equalsIgnoreCase(CRERATE_NEW_COLLECTION_STRING)) {
      return;
    }

    String targetKeyColName = this.targetColumnList.getSelectedValue();

    if (rootNetwork == null) {
      return;
    }

    Iterator<CyNode> it = rootNetwork.getNodeList().iterator();

    while (it.hasNext()) {
      CyNode node = it.next();
      Object keyValue = rootNetwork.getRow(node).getRaw(targetKeyColName);
      this.nMap.put(keyValue, node);
    }
  }
Exemplo n.º 9
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;
  }