use of org.cytoscape.work.json.JSONResult 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;
}
use of org.cytoscape.work.json.JSONResult in project cytoscape-impl by cytoscape.
the class ListAvailableTask method getResults.
@SuppressWarnings({ "unchecked" })
@Override
public <R> R getResults(Class<? extends R> type) {
if (type.equals(JSONResult.class)) {
JSONResult res = () -> {
StringBuilder stringBuilder = new StringBuilder("[");
int count = webAppList.size();
int index = 0;
for (WebApp app : webAppList) {
stringBuilder.append("{\"appName\": \"" + app.getName() + "\",");
stringBuilder.append("\"description\": " + Utils.quote(app.getDescription()) + ",");
if (app.getDetails() != null)
stringBuilder.append("\"details\": " + Utils.quote(app.getDetails()) + "}");
else
stringBuilder.append("\"details\": \"\"}");
index++;
if (index < count)
stringBuilder.append(",");
}
stringBuilder.append("]");
// System.out.println(stringBuilder.toString());
return stringBuilder.toString();
};
return (R) res;
} else if (type.equals(String.class)) {
List<String> appList = new ArrayList<String>(webAppList.size());
Map<String, WebApp> appMap = new HashMap<String, WebApp>();
for (WebApp app : webAppList) {
appList.add(app.getFullName().toLowerCase());
appMap.put(app.getFullName().toLowerCase(), app);
}
Collections.sort(appList);
String list = "";
for (String app : appList) {
WebApp thisApp = appMap.get(app);
list += "name: " + thisApp.getFullName() + ", version: " + getVersion(thisApp) + "\n";
}
return (R) list;
} else if (type.equals(List.class)) {
List<String> list = new ArrayList<>();
for (WebApp app : webAppList) {
list.add(app.getFullName());
}
return (R) list;
}
return null;
}
use of org.cytoscape.work.json.JSONResult 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;
}
use of org.cytoscape.work.json.JSONResult in project cytoscape-impl by cytoscape.
the class RegisterNetworkTask method getResults.
@Override
public Object getResults(Class type) {
if (type.equals(List.class)) {
return views;
} else if (type.equals(String.class)) {
if (networks == null)
return null;
String res = "";
if (views != null && views.size() > 0) {
res += "Views:\n";
for (CyNetworkView view : views) {
res += " " + DataUtils.getViewTitle(view) + " (SUID: " + view.getSUID() + ")" + "\n";
}
}
res += "Networks:\n";
for (CyNetwork network : networks) {
res += " " + DataUtils.getNetworkName(network) + " (SUID: " + network.getSUID() + ")" + "\n";
}
return res;
} else if (type.equals(CyNetwork.class))
return networks.get(0);
else if (type.equals(CyNetworkView.class)) {
if (views != null && views.size() > 0)
return views.get(0);
else
return null;
} else if (type.equals(JSONResult.class)) {
JSONResult res = () -> {
if (networks == null)
return "{}";
else if (singleton) {
// Special case single network
CyNetwork network = networks.get(0);
CyNetworkView view = null;
if (views.size() == 1)
view = views.get(0);
String strRes = jsonNetView(network, view);
return jsonNetView(network, view);
} else {
String strRes = "[";
Set<CyNetwork> viewNets = new HashSet<>();
boolean first = true;
for (CyNetworkView view : views) {
CyNetwork net = view.getModel();
viewNets.add(net);
if (!first)
strRes += ",";
else
first = false;
strRes += jsonNetView(net, view);
}
for (CyNetwork net : networks) {
if (!viewNets.contains(net)) {
strRes += jsonNetView(net, null);
}
}
strRes += "]";
return strRes;
}
};
return res;
}
return null;
}
use of org.cytoscape.work.json.JSONResult in project cytoscape-impl by cytoscape.
the class DeselectTask method getResults.
public Object getResults(Class type) {
List<CyIdentifiable> identifiables = new ArrayList<>();
if (deselectedNodes != null && deselectedNodes.size() > 0) {
identifiables.addAll(deselectedNodes);
}
if (deselectedEdges != null && deselectedEdges.size() > 0) {
identifiables.addAll(deselectedEdges);
}
if (type.equals(List.class)) {
return identifiables;
} else if (type.equals(String.class)) {
if (identifiables.size() == 0)
return "<none>";
String ret = "";
if (deselectedNodes != null && deselectedNodes.size() > 0) {
ret += "Nodes deselected: \n";
for (CyNode node : deselectedNodes) {
ret += " " + network.getRow(node).get(CyNetwork.NAME, String.class) + "\n";
}
}
if (deselectedEdges != null && deselectedEdges.size() > 0) {
ret += "Edges deselected: \n";
for (CyEdge edge : deselectedEdges) {
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 {
String result = "{\"nodes\":";
if (deselectedNodes == null || deselectedNodes.size() == 0)
result += "[]";
else
result += cyJSONUtil.cyIdentifiablesToJson(deselectedNodes);
result += ", \"edges\":";
if (deselectedEdges == null || deselectedEdges.size() == 0)
result += "[]";
else
result += cyJSONUtil.cyIdentifiablesToJson(deselectedEdges);
return result + "}";
}
};
return res;
}
return identifiables;
}
Aggregations