use of org.apache.rya.shell.SharedShellState.ShellState in project incubator-rya by apache.
the class RyaCommands method sparqlQuery.
@CliCommand(value = SPARQL_QUERY_CMD, help = "Executes the provided SPARQL Query on the connected Rya instance.")
public String sparqlQuery(@CliOption(key = { "file" }, mandatory = false, help = "A local file containing the SPARQL Query that is to be read and executed.") final String file) {
// Fetch the command that is connected to the store.
final ShellState shellState = state.getShellState();
final RyaClient commands = shellState.getConnectedCommands().get();
final Optional<String> ryaInstanceName = shellState.getRyaInstanceName();
try {
// file option specified
String sparqlQuery;
if (file != null) {
sparqlQuery = new String(Files.readAllBytes(new File(file).toPath()), StandardCharsets.UTF_8);
consolePrinter.println("Loaded Query:");
consolePrinter.println(sparqlQuery);
} else {
// No Options specified. Show the user the SPARQL Prompt
final Optional<String> sparqlQueryOpt = sparqlPrompt.getSparql();
if (sparqlQueryOpt.isPresent()) {
sparqlQuery = sparqlQueryOpt.get();
} else {
// user aborted the SPARQL prompt.
return "";
}
}
consolePrinter.println("Executing Query...");
consolePrinter.flush();
return commands.getExecuteSparqlQuery().executeSparqlQuery(ryaInstanceName.get(), sparqlQuery);
} catch (final RyaClientException | IOException e) {
log.error("Error", e);
throw new RuntimeException("Can not execute the SPARQL Query. Reason: " + e.getMessage(), e);
}
}
use of org.apache.rya.shell.SharedShellState.ShellState in project incubator-rya by apache.
the class SharedShellStateTest method connectedToInstance.
@Test
public void connectedToInstance() {
final SharedShellState state = new SharedShellState();
// Connect to Accumulo.
final AccumuloConnectionDetails connectionDetails = mock(AccumuloConnectionDetails.class);
final RyaClient connectedCommands = mock(RyaClient.class);
state.connectedToAccumulo(connectionDetails, connectedCommands);
// Connect to an Instance.
state.connectedToInstance("instance");
// Verify the state.
final ShellState expected = ShellState.builder().setConnectionState(ConnectionState.CONNECTED_TO_INSTANCE).setAccumuloDetails(connectionDetails).setConnectedCommands(connectedCommands).setRyaInstanceName("instance").build();
assertEquals(expected, state.getShellState());
}
use of org.apache.rya.shell.SharedShellState.ShellState in project incubator-rya by apache.
the class SharedShellStateTest method disconnected.
@Test
public void disconnected() {
final SharedShellState state = new SharedShellState();
// Connect to Accumulo and an instance.
final AccumuloConnectionDetails connectionDetails = mock(AccumuloConnectionDetails.class);
final RyaClient connectedCommands = mock(RyaClient.class);
state.connectedToAccumulo(connectionDetails, connectedCommands);
state.connectedToInstance("instance");
// Disconnect.
state.disconnected();
// Verify the state.
final ShellState expected = ShellState.builder().setConnectionState(ConnectionState.DISCONNECTED).build();
assertEquals(expected, state.getShellState());
}
use of org.apache.rya.shell.SharedShellState.ShellState in project incubator-rya by apache.
the class SharedShellStateTest method disconnectedToConnectedToStorage.
@Test
public void disconnectedToConnectedToStorage() {
final SharedShellState state = new SharedShellState();
// Connect to Accumulo.
final AccumuloConnectionDetails connectionDetails = mock(AccumuloConnectionDetails.class);
final RyaClient connectedCommands = mock(RyaClient.class);
state.connectedToAccumulo(connectionDetails, connectedCommands);
// Verify the state.
final ShellState expected = ShellState.builder().setConnectionState(ConnectionState.CONNECTED_TO_STORAGE).setAccumuloDetails(connectionDetails).setConnectedCommands(connectedCommands).build();
assertEquals(expected, state.getShellState());
}
Aggregations