use of org.cytoscape.work.json.JSONResult in project cytoscape-impl by cytoscape.
the class GenerateNetworkViewsTask method getResults.
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Object getResults(Class expectedType) {
if (expectedType.equals(String.class))
return getStringResults();
else if (expectedType.equals(JSONResult.class)) {
JSONResult res = () -> {
if (results == null && largeNetworks.isEmpty())
return "{}";
else {
CyJSONUtil cyJSONUtil = serviceRegistrar.getService(CyJSONUtil.class);
List<CyNetwork> networks = new ArrayList<>();
for (CyNetworkView view : results) networks.add(view.getModel());
networks.addAll(largeNetworks);
String jsonRes = "{ \"networks\":";
jsonRes += cyJSONUtil.cyIdentifiablesToJson(networks);
jsonRes += ", \"views\":";
jsonRes += cyJSONUtil.cyIdentifiablesToJson(results) + "}";
return jsonRes;
}
};
return res;
}
return results;
}
use of org.cytoscape.work.json.JSONResult in project cytoscape-impl by cytoscape.
the class GroupNodesTask method getResults.
@Override
public Object getResults(Class requestedType) {
if (newGroup == null)
return null;
if (requestedType.equals(CyGroup.class))
return newGroup;
if (requestedType.equals(String.class))
return newGroup.toString();
if (requestedType.equals(JSONResult.class)) {
CyJSONUtil jsonUtil = serviceRegistrar.getService(CyJSONUtil.class);
JSONResult res = () -> {
if (newGroup == null)
return "{}";
return "{\"group\":" + newGroup.getGroupNode().getSUID() + "}";
/*
String val = "{\"group\":"+newGroup.getGroupNode().getSUID();
List<CyNode> nodes = newGroup.getNodeList();
if (nodes != null && nodes.size() > 0)
val += "\"nodes\":"+jsonUtil.cyIdentifiablesToJson(nodes);
return val+"}";
*/
};
return res;
}
return null;
}
use of org.cytoscape.work.json.JSONResult in project cytoscape-impl by cytoscape.
the class HideCommandTask 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 hidden: \n";
for (CyNode node : nodes) {
ret += " " + network.getRow(node).get(CyNetwork.NAME, String.class) + "\n";
}
}
if (edges != null && edges.size() > 0) {
ret += "Edges hidden: \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;
}
use of org.cytoscape.work.json.JSONResult 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;
}
use of org.cytoscape.work.json.JSONResult 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;
}
Aggregations