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();
}
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;
}
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();
}
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;
}
Aggregations