Search in sources :

Example 6 with CyJSONUtil

use of org.cytoscape.util.json.CyJSONUtil in project cytoscape-impl by cytoscape.

the class ImportTableDataTask method getResults.

@Override
public Object getResults(Class requestedType) {
    if (requestedType.equals(List.class))
        return mappedTables;
    if (requestedType.equals(String.class)) {
        String str = "Mapped to tables:\n";
        for (CyTable table : mappedTables) {
            str += "   " + table.toString() + "\n";
        }
        return str;
    }
    if (requestedType.equals(JSONResult.class)) {
        CyJSONUtil cyJSONUtil = serviceRegistrar.getService(CyJSONUtil.class);
        JSONResult res = () -> {
            if (mappedTables.isEmpty())
                return "{}";
            return "{\"mappedTables\":" + cyJSONUtil.cyIdentifiablesToJson(mappedTables) + "}";
        };
        return res;
    }
    return null;
}
Also used : CyTable(org.cytoscape.model.CyTable) JSONResult(org.cytoscape.work.json.JSONResult) CyJSONUtil(org.cytoscape.util.json.CyJSONUtil)

Example 7 with CyJSONUtil

use of org.cytoscape.util.json.CyJSONUtil in project cytoscape-impl by cytoscape.

the class GetNodeAttributeTask method getResults.

public Object getResults(Class requestedType) {
    if (requestedType.equals(String.class)) {
        return DataUtils.convertMapToString(nodeDataMap);
    } else if (requestedType.equals(JSONResult.class)) {
        JSONResult res = () -> {
            if (nodeDataMap == null)
                return "[]";
            else {
                StringBuilder output = new StringBuilder("[");
                CyJSONUtil cyJSONUtil = serviceRegistrar.getService(CyJSONUtil.class);
                List<CyColumn> cyColumn = columnTunable.getColumnList(nodeTable);
                CyColumn[] cyColumnArray = cyColumn.size() > 0 ? cyColumn.toArray(new CyColumn[0]) : new CyColumn[] {};
                int count = nodeDataMap.size();
                for (CyIdentifiable node : nodeDataMap.keySet()) {
                    CyRow row = nodeTable.getRow(node.getSUID());
                    output.append(" " + cyJSONUtil.toJson(row, cyColumnArray));
                    if (count > 1) {
                        output.append(",\n");
                    }
                    count--;
                }
                output.append("\n]");
                return output.toString();
            }
        };
        return res;
    }
    return nodeDataMap;
}
Also used : JSONResult(org.cytoscape.work.json.JSONResult) CyColumn(org.cytoscape.model.CyColumn) CyRow(org.cytoscape.model.CyRow) CyJSONUtil(org.cytoscape.util.json.CyJSONUtil) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 8 with CyJSONUtil

use of org.cytoscape.util.json.CyJSONUtil in project cytoscape-impl by cytoscape.

the class GetEdgeAttributeTask method getResults.

public Object getResults(Class requestedType) {
    if (requestedType.equals(String.class)) {
        return DataUtils.convertMapToString(edgeDataMap);
    } else if (requestedType.equals(JSONResult.class)) {
        JSONResult res = () -> {
            if (edgeDataMap == null)
                return "[]";
            else {
                StringBuilder output = new StringBuilder("[");
                CyJSONUtil cyJSONUtil = serviceRegistrar.getService(CyJSONUtil.class);
                List<CyColumn> cyColumn = columnTunable.getColumnList(edgeTable);
                CyColumn[] cyColumnArray = cyColumn.size() > 0 ? cyColumn.toArray(new CyColumn[0]) : new CyColumn[] {};
                int count = edgeDataMap.size();
                for (CyIdentifiable edge : edgeDataMap.keySet()) {
                    CyRow row = edgeTable.getRow(edge.getSUID());
                    output.append(" " + cyJSONUtil.toJson(row, cyColumnArray));
                    if (count > 1) {
                        output.append(",\n");
                    }
                    count--;
                }
                output.append("\n]");
                return output.toString();
            }
        };
        return res;
    }
    return edgeDataMap;
}
Also used : JSONResult(org.cytoscape.work.json.JSONResult) CyColumn(org.cytoscape.model.CyColumn) CyRow(org.cytoscape.model.CyRow) CyJSONUtil(org.cytoscape.util.json.CyJSONUtil) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 9 with CyJSONUtil

use of org.cytoscape.util.json.CyJSONUtil in project cytoscape-impl by cytoscape.

the class AddTask method getResults.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Object getResults(Class type) {
    List<CyIdentifiable> identifiables = new ArrayList();
    if (nodeList != null)
        identifiables.addAll(nodeList);
    if (edgeList != null)
        identifiables.addAll(edgeList);
    if (type.equals(List.class)) {
        return identifiables;
    } else if (type.equals(String.class)) {
        if (identifiables.size() == 0)
            return "<none>";
        String ret = "";
        if (nodeList != null && nodeList.size() > 0) {
            ret += "Nodes added: \n";
            for (CyNode node : nodeList) {
                ret += "   " + network.getRow(node).get(CyNetwork.NAME, String.class) + "\n";
            }
        }
        if (edgeList != null && edgeList.size() > 0) {
            ret += "Edges added: \n";
            for (CyEdge edge : edgeList) {
                ret += "   " + network.getRow(edge).get(CyNetwork.NAME, String.class) + "\n";
            }
        }
        return ret;
    } else if (type.equals(JSONResult.class)) {
        JSONResult res = () -> {
            if (identifiables == null || identifiables.size() == 0)
                return "{}";
            else {
                CyJSONUtil cyJSONUtil = serviceRegistrar.getService(CyJSONUtil.class);
                String result = "{\"nodes\":";
                if (nodeList == null || nodeList.size() == 0)
                    result += "[]";
                else
                    result += cyJSONUtil.cyIdentifiablesToJson(nodeList);
                result += ", \"edges\":";
                if (edgeList == null || edgeList.size() == 0)
                    result += "[]";
                else
                    result += cyJSONUtil.cyIdentifiablesToJson(edgeList);
                result += "}";
                return result;
            }
        };
        return res;
    }
    return identifiables;
}
Also used : JSONResult(org.cytoscape.work.json.JSONResult) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CyIdentifiable(org.cytoscape.model.CyIdentifiable) CyJSONUtil(org.cytoscape.util.json.CyJSONUtil)

Example 10 with CyJSONUtil

use of org.cytoscape.util.json.CyJSONUtil in project cytoscape-impl by cytoscape.

the class GetNetworkAttributeTask method getResults.

public Object getResults(Class requestedType) {
    if (requestedType.equals(String.class)) {
        return DataUtils.convertMapToString(networkData);
    } else if (requestedType.equals(JSONResult.class)) {
        JSONResult res = () -> {
            if (networkData == null)
                return "[]";
            else {
                StringBuilder output = new StringBuilder("[");
                CyJSONUtil cyJSONUtil = serviceRegistrar.getService(CyJSONUtil.class);
                List<CyColumn> cyColumn = columnTunable.getColumnList(networkTable);
                CyColumn[] cyColumnArray = cyColumn.size() > 0 ? cyColumn.toArray(new CyColumn[0]) : new CyColumn[] {};
                CyRow row = networkTable.getRow(network.getSUID());
                output.append(" " + cyJSONUtil.toJson(row, cyColumnArray));
                output.append("\n]");
                return output.toString();
            }
        };
        return res;
    }
    return networkData;
}
Also used : JSONResult(org.cytoscape.work.json.JSONResult) CyColumn(org.cytoscape.model.CyColumn) CyRow(org.cytoscape.model.CyRow) CyJSONUtil(org.cytoscape.util.json.CyJSONUtil)

Aggregations

CyJSONUtil (org.cytoscape.util.json.CyJSONUtil)10 JSONResult (org.cytoscape.work.json.JSONResult)10 CyIdentifiable (org.cytoscape.model.CyIdentifiable)6 ArrayList (java.util.ArrayList)5 CyEdge (org.cytoscape.model.CyEdge)4 CyNode (org.cytoscape.model.CyNode)4 CyColumn (org.cytoscape.model.CyColumn)3 CyRow (org.cytoscape.model.CyRow)3 CyNetwork (org.cytoscape.model.CyNetwork)1 CyTable (org.cytoscape.model.CyTable)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1