private void mergeTables(
      final CyTable source, final CyTable target, final Class<? extends CyIdentifiable> type) {
    CyColumn sourceKey = source.getPrimaryKey();
    CyColumn targetKey = target.getPrimaryKey();
    String keyName = sourceKey.getName();

    // Make sure keys match
    if (keyName.equals(targetKey.getName())) {
      // Merge columns first, because even if the source table has no rows to merge,
      // the columns have to be restored
      mergeColumns(keyName, source, target);

      for (CyRow sourceRow : source.getAllRows()) {
        if (cancelled) return;

        Long key = sourceRow.get(keyName, Long.class);
        CyIdentifiable entry = cache.getObjectById(key, type);
        Long mappedKey = entry != null ? entry.getSUID() : null;

        if (mappedKey == null) mappedKey = key;

        CyRow targetRow = target.getRow(mappedKey);
        mergeRow(keyName, sourceRow, targetRow);
      }
    }
  }
  @Override
  public boolean handleIt(
      final CyIdentifiable to,
      final CyColumn toColumn,
      final Map<CyIdentifiable, CyColumn> mapFromGOFromAttr) {

    if (to == null || toColumn == null || mapFromGOFromAttr == null) {
      throw new java.lang.NullPointerException("All parameters should not be null.");
    }

    final CyTable table = toColumn.getTable();
    final CyRow row = table.getRow(to.getSUID());
    final ColumnType type = ColumnType.getType(toColumn);

    if (type == ColumnType.STRING) {
      final String toValue = row.get(toColumn.getName(), String.class);
      final Set<String> values = new TreeSet<String>();
      values.add(toValue);

      for (Map.Entry<CyIdentifiable, CyColumn> entry : mapFromGOFromAttr.entrySet()) {
        final CyIdentifiable from = entry.getKey();
        final CyColumn fromColumn = entry.getValue();
        final CyRow fromRow = fromColumn.getTable().getRow(from.getSUID());

        // TODO figure out which network to be using
        String fromValue = fromRow.get(fromColumn.getName(), String.class);
        if (fromValue != null) {
          values.add(fromValue.toString());
        }
      }

      StringBuilder str = new StringBuilder();
      for (String v : values) {
        str.append(v + ";");
      }

      str.deleteCharAt(str.length() - 1);
      row.set(toColumn.getName(), str.toString());

      return true;
    }

    // FIXME: how about Integer, Double, Boolean?
    return false;
  }
示例#3
0
  protected final String getGraphObject(final CyNetwork network, final CyIdentifiable obj) {
    final CyRow row = network.getRow(obj);

    try {
      return this.serializer.serializeGraphObject(obj, row);
    } catch (IOException e) {
      throw getError(
          "Could not serialize graph object with SUID: " + obj.getSUID(),
          e,
          Response.Status.INTERNAL_SERVER_ERROR);
    }
  }