use of au.gov.asd.tac.constellation.webserver.restapi.RestServiceException in project constellation by constellation-app.
the class GetAttributes method callService.
@Override
public void callService(final PluginParameters parameters, InputStream in, OutputStream out) throws IOException {
final String graphId = parameters.getStringValue(GRAPH_ID_PARAMETER_ID);
final Graph graph = graphId == null ? RestUtilities.getActiveGraph() : GraphNode.getGraph(graphId);
if (graph == null) {
throw new RestServiceException(HTTP_UNPROCESSABLE_ENTITY, "No graph with id " + graphId);
}
final ObjectMapper mapper = new ObjectMapper();
final ObjectNode root = mapper.createObjectNode();
final ReadableGraph rg = graph.getReadableGraph();
try {
final int gCount = rg.getAttributeCount(GraphElementType.GRAPH);
for (int i = 0; i < gCount; i++) {
final int attrId = rg.getAttribute(GraphElementType.GRAPH, i);
final String type = rg.getAttributeType(attrId);
final String label = rg.getAttributeName(attrId);
root.put(String.format("graph.%s", label), type);
}
final int vCount = rg.getAttributeCount(GraphElementType.VERTEX);
for (int i = 0; i < vCount; i++) {
final int attrId = rg.getAttribute(GraphElementType.VERTEX, i);
final String type = rg.getAttributeType(attrId);
final String label = rg.getAttributeName(attrId);
root.put(String.format("source.%s", label), type);
}
final int tCount = rg.getAttributeCount(GraphElementType.TRANSACTION);
for (int i = 0; i < tCount; i++) {
final int attrId = rg.getAttribute(GraphElementType.TRANSACTION, i);
final String type = rg.getAttributeType(attrId);
final String label = rg.getAttributeName(attrId);
root.put(String.format("transaction.%s", label), type);
}
} finally {
rg.release();
}
mapper.writeValue(out, root);
}
use of au.gov.asd.tac.constellation.webserver.restapi.RestServiceException in project constellation by constellation-app.
the class GetGraphValues method callService.
@Override
public void callService(final PluginParameters parameters, InputStream in, OutputStream out) throws IOException {
final String graphId = parameters.getStringValue(GRAPH_ID_PARAMETER_ID);
final Graph graph = graphId == null ? RestUtilities.getActiveGraph() : GraphNode.getGraph(graphId);
if (graph == null) {
throw new RestServiceException(HTTP_UNPROCESSABLE_ENTITY, "No graph with id " + graphId);
}
final ObjectMapper mapper = new ObjectMapper();
final ObjectNode root = mapper.createObjectNode();
final ArrayNode columns = root.putArray("columns");
final ArrayNode data = root.putArray("data");
final ArrayNode row = data.addArray();
final ReadableGraph rg = graph.getReadableGraph();
try {
final int gCount = rg.getAttributeCount(GraphElementType.GRAPH);
for (int i = 0; i < gCount; i++) {
final int attrId = rg.getAttribute(GraphElementType.GRAPH, i);
final String type = rg.getAttributeType(attrId);
final String label = rg.getAttributeName(attrId);
String value = rg.getStringValue(attrId, 0);
columns.add(String.format("%s|%s", label, type));
RestUtilities.addData(row, type, value);
}
} finally {
rg.release();
}
mapper.writeValue(out, root);
}
use of au.gov.asd.tac.constellation.webserver.restapi.RestServiceException in project constellation by constellation-app.
the class SetGraph method callService.
@Override
public void callService(final PluginParameters parameters, InputStream in, OutputStream out) throws IOException {
final String graphId = parameters.getStringValue(GRAPH_ID_PARAMETER_ID);
final GraphNode graphNode = GraphNode.getGraphNode(graphId);
if (graphNode != null) {
try {
SwingUtilities.invokeAndWait(() -> graphNode.getTopComponent().requestActive());
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
throw new RestServiceException(ex);
} catch (final InvocationTargetException ex) {
throw new RestServiceException(ex);
}
} else {
throw new RestServiceException(HTTP_UNPROCESSABLE_ENTITY, "No graph with id " + graphId);
}
}
use of au.gov.asd.tac.constellation.webserver.restapi.RestServiceException in project constellation by constellation-app.
the class FileListener method parseAndExecute.
/**
* Execute a REST endpoint.
*
* @param node A JSON node representing the input parameters.
*
* @throws Exception because of AutoCloseable
*/
private void parseAndExecute(final String verb, final String endpoint, final String path, final JsonNode args) throws Exception {
if ("/v2/service".equals(endpoint)) {
final HttpMethod httpMethod = HttpMethod.getValue(verb);
// Get an instance of the service (if it exists).
//
final RestService rs = RestServiceRegistry.get(path, httpMethod);
// Convert the arguments to PluginParameters.
//
final PluginParameters parameters = rs.createParameters();
RestServiceUtilities.parametersFromJson((ObjectNode) args, parameters);
try (final InStream ins = new InStream(restPath, CONTENT_IN, true);
final OutputStream out = outStream(restPath, CONTENT_OUT)) {
rs.callService(parameters, ins.in, out);
} catch (final IOException | RuntimeException ex) {
throw new RestServiceException(ex);
}
} else {
unrec(ENDPOINT, endpoint);
}
}
Aggregations