Search in sources :

Example 16 with JSONResult

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

the class DestroyNetworkViewTask method getResults.

/**
 * Returns the SUID's of destroyed views.
 */
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Object getResults(Class type) {
    if (type == String.class) {
        StringBuilder sb = new StringBuilder();
        if (destroyedSUIDs != null && !destroyedSUIDs.isEmpty()) {
            sb.append("Destroyed views:\n");
            destroyedSUIDs.forEach((suid, title) -> {
                sb.append(title + " (SUID: " + suid + ")" + "\n");
            });
            sb.substring(0, sb.length() - 1);
        } else {
            sb.append("No views were destroyed.");
        }
        return sb.toString();
    }
    if (type == JSONResult.class) {
        JsonArray jsonArr = new JsonArray();
        JsonObject jsonObject = new JsonObject();
        if (destroyedSUIDs != null && !destroyedSUIDs.isEmpty()) {
            destroyedSUIDs.keySet().forEach(suid -> {
                jsonArr.add(new JsonPrimitive(suid));
            });
        }
        jsonObject.add("views", jsonArr);
        String json = new Gson().toJson(jsonObject);
        JSONResult res = () -> {
            return json;
        };
        return res;
    }
    return destroyedSUIDs != null ? new ArrayList<>(destroyedSUIDs.keySet()) : Collections.emptyList();
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JSONResult(org.cytoscape.work.json.JSONResult) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson)

Example 17 with JSONResult

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

the class GetCurrentNetworkViewTask method getResults.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Object getResults(Class type) {
    if (type == String.class)
        return view != null ? view.toString() : null;
    if (type == JSONResult.class) {
        String json = view != null ? serviceRegistrar.getService(CyJSONUtil.class).toJson(view) : null;
        JSONResult res = () -> {
            return "{ \"view\":" + json + "}";
        };
        return res;
    }
    return view;
}
Also used : JSONResult(org.cytoscape.work.json.JSONResult)

Example 18 with JSONResult

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

the class ApplyVisualStyleTask method getResults.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Object getResults(Class type) {
    if (type == String.class) {
        String res = "";
        if (networkViews != null && !networkViews.isEmpty()) {
            res += "Style applied to views:\n";
            for (CyNetworkView view : networkViews) res += DataUtils.getViewTitle(view) + " (SUID: " + view.getSUID() + ")" + "\n";
            res = res.substring(0, res.length() - 1);
        } else {
            res = "Please select one or more views before applying a style.";
        }
        return res;
    }
    if (type == JSONResult.class) {
        String json = serviceRegistrar.getService(CyJSONUtil.class).cyIdentifiablesToJson(networkViews);
        JSONResult res = () -> {
            return "{\"views\":" + json + "}";
        };
        return res;
    }
    return networkViews != null ? new ArrayList<>(networkViews) : Collections.emptyList();
}
Also used : JSONResult(org.cytoscape.work.json.JSONResult) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyJSONUtil(org.cytoscape.util.json.CyJSONUtil)

Example 19 with JSONResult

use of org.cytoscape.work.json.JSONResult 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

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