Search in sources :

Example 1 with JSONResult

use of org.cytoscape.work.json.JSONResult in project cytoscape-impl by cytoscape.

the class TunableAbstractCyWriter method getResults.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Object getResults(Class type) {
    if (type == String.class) {
        String res = null;
        if (// TODO: should check if file exists
        outputFile != null)
            /*&& outputFile.exists()*/
            res = "Output File: " + outputFile.getAbsolutePath();
        return res;
    }
    if (type == JSONResult.class) {
        JsonObject jsonObj = new JsonObject();
        jsonObj.addProperty("file", outputFile != null ? /*&& outputFile.exists()*/
        outputFile.getAbsolutePath() : null);
        String json = new Gson().toJson(jsonObj);
        JSONResult res = () -> {
            return json;
        };
        return res;
    }
    return outputFile;
}
Also used : JSONResult(org.cytoscape.work.json.JSONResult) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson)

Example 2 with JSONResult

use of org.cytoscape.work.json.JSONResult in project cytoscape-impl by cytoscape.

the class DestroyNetworkTask method getResults.

@Override
public Object getResults(Class type) {
    if (localNets == null)
        return null;
    if (type.equals(String.class)) {
        String res = "Destroyed network";
        if (localNets.size() > 1)
            res += "s";
        res += ":\n";
        for (CyNetwork net : localNets) res += "    " + net.toString() + "\n";
        return res;
    } else if (type.equals(CyNetwork.class)) {
        return localNets.get(0);
    } else if (type.equals(List.class)) {
        return localNets;
    } else if (type.equals(JSONResult.class)) {
        JSONResult res = () -> {
            if (localNets == null)
                return "{}";
            else {
                return "{\"network\":" + localNets.get(0).getSUID() + "}";
            }
        };
        return res;
    }
    return null;
}
Also used : JSONResult(org.cytoscape.work.json.JSONResult) CyNetwork(org.cytoscape.model.CyNetwork)

Example 3 with JSONResult

use of org.cytoscape.work.json.JSONResult in project cytoscape-impl by cytoscape.

the class UnHideCommandTask method getResults.

public Object getResults(Class type) {
    List<CyIdentifiable> identifiables = new ArrayList<>();
    if (nodes != null)
        identifiables.addAll(nodes);
    if (edges != null)
        identifiables.addAll(edges);
    if (type.equals(List.class)) {
        return identifiables;
    } else if (type.equals(String.class)) {
        if (identifiables.size() == 0)
            return "<none>";
        String ret = "";
        if (nodes != null && nodes.size() > 0) {
            ret += "Nodes unhidden: \n";
            for (CyNode node : nodes) {
                ret += "   " + network.getRow(node).get(CyNetwork.NAME, String.class) + "\n";
            }
        }
        if (edges != null && edges.size() > 0) {
            ret += "Edges unhidden: \n";
            for (CyEdge edge : edges) {
                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 (nodes == null || nodes.size() == 0)
                    result += "[]";
                else
                    result += cyJSONUtil.cyIdentifiablesToJson(nodes);
                result += ", \"edges\":";
                if (edges == null || edges.size() == 0)
                    result += "[]";
                else
                    result += cyJSONUtil.cyIdentifiablesToJson(edges);
                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 4 with JSONResult

use of org.cytoscape.work.json.JSONResult in project cytoscape-impl by cytoscape.

the class ListNetworkViewsTask method getResults.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Object getResults(Class type) {
    if (type == String.class)
        return DataUtils.convertData(views);
    if (type == JSONResult.class) {
        String json = serviceRegistrar.getService(CyJSONUtil.class).cyIdentifiablesToJson(views);
        JSONResult res = () -> {
            return "{\"views\":" + json + "}";
        };
        return res;
    }
    return views;
}
Also used : JSONResult(org.cytoscape.work.json.JSONResult) CyJSONUtil(org.cytoscape.util.json.CyJSONUtil)

Example 5 with JSONResult

use of org.cytoscape.work.json.JSONResult in project cytoscape-impl by cytoscape.

the class SelectTask method getResults.

public Object getResults(Class type) {
    List<CyIdentifiable> identifiables = new ArrayList();
    if (selectedNodes != null)
        identifiables.addAll(selectedNodes);
    if (selectedEdges != null)
        identifiables.addAll(selectedEdges);
    if (type.equals(List.class)) {
        return identifiables;
    } else if (type.equals(String.class)) {
        if (identifiables.size() == 0)
            return "<none>";
        String ret = "";
        if (selectedNodes != null && selectedNodes.size() > 0) {
            ret += "Nodes selected: \n";
            for (CyNode node : selectedNodes) {
                ret += "   " + network.getRow(node).get(CyNetwork.NAME, String.class) + "\n";
            }
        }
        if (selectedEdges != null && selectedEdges.size() > 0) {
            ret += "Edges selected: \n";
            for (CyEdge edge : selectedEdges) {
                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 = registrar.getService(CyJSONUtil.class);
                String result = "{\"nodes\":";
                if (selectedNodes == null || selectedNodes.size() == 0)
                    result += "[]";
                else
                    result += cyJSONUtil.cyIdentifiablesToJson(selectedNodes);
                result += ", \"edges\":";
                if (selectedEdges == null || selectedEdges.size() == 0)
                    result += "[]";
                else
                    result += cyJSONUtil.cyIdentifiablesToJson(selectedEdges);
                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)

Aggregations

JSONResult (org.cytoscape.work.json.JSONResult)19 CyJSONUtil (org.cytoscape.util.json.CyJSONUtil)12 ArrayList (java.util.ArrayList)7 CyIdentifiable (org.cytoscape.model.CyIdentifiable)7 CyEdge (org.cytoscape.model.CyEdge)5 CyNode (org.cytoscape.model.CyNode)5 CyColumn (org.cytoscape.model.CyColumn)3 CyNetwork (org.cytoscape.model.CyNetwork)3 CyRow (org.cytoscape.model.CyRow)3 CyNetworkView (org.cytoscape.view.model.CyNetworkView)3 Gson (com.google.gson.Gson)2 JsonObject (com.google.gson.JsonObject)2 JsonArray (com.google.gson.JsonArray)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 WebApp (org.cytoscape.app.internal.net.WebApp)1 CyTable (org.cytoscape.model.CyTable)1