RYA-362 Improved UX for case where create-pcj is called without args. Closes #223
diff --git a/extras/shell/src/main/java/org/apache/rya/shell/RyaAdminCommands.java b/extras/shell/src/main/java/org/apache/rya/shell/RyaAdminCommands.java
index 7d0ab79..db81096 100644
--- a/extras/shell/src/main/java/org/apache/rya/shell/RyaAdminCommands.java
+++ b/extras/shell/src/main/java/org/apache/rya/shell/RyaAdminCommands.java
@@ -290,9 +290,9 @@
@CliCommand(value = CREATE_PCJ_CMD, help = "Creates and starts the maintenance of a new PCJ using a Fluo application.")
public String createPcj(
- @CliOption(key = {"exportToRya"}, mandatory = false, help = "Indicates that results for the query should be exported to a Rya PCJ table.")
+ @CliOption(key = {"exportToRya"}, mandatory = false, help = "Indicates that results for the query should be exported to a Rya PCJ table.", unspecifiedDefaultValue = "false", specifiedDefaultValue = "true")
boolean exportToRya,
- @CliOption(key = {"exportToKafka"}, mandatory = false, help = "Indicates that results for the query should be exported to a Kafka Topic.")
+ @CliOption(key = {"exportToKafka"}, mandatory = false, help = "Indicates that results for the query should be exported to a Kafka Topic.", unspecifiedDefaultValue = "false", specifiedDefaultValue = "true")
boolean exportToKafka) {
// Fetch the command that is connected to the store.
final ShellState shellState = state.getShellState();
@@ -300,19 +300,20 @@
final String ryaInstance = shellState.getRyaInstanceName().get();
try {
+ final Set<ExportStrategy> strategies = new HashSet<>();
+ if(exportToRya) {
+ strategies.add(ExportStrategy.RYA);
+ }
+ if(exportToKafka) {
+ strategies.add(ExportStrategy.KAFKA);
+ }
+ if(strategies.isEmpty()) {
+ return "The user must specify at least one export strategy: (--exportToRya, --exportToKafka)";
+ }
+
// Prompt the user for the SPARQL.
final Optional<String> sparql = sparqlPrompt.getSparql();
if (sparql.isPresent()) {
- Set<ExportStrategy> strategies = new HashSet<>();
- if(exportToRya) {
- strategies.add(ExportStrategy.RYA);
- }
- if(exportToKafka) {
- strategies.add(ExportStrategy.KAFKA);
- }
- if(strategies.size() == 0) {
- return "The user must specify at least one export strategy by setting either exportToRya or exportToKafka to true.";
- }
// Execute the command.
final String pcjId = commands.getCreatePCJ().createPCJ(ryaInstance, sparql.get(), strategies);
// Return a message that indicates the ID of the newly created ID.
diff --git a/extras/shell/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java b/extras/shell/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java
index f08e02a..1249536 100644
--- a/extras/shell/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java
+++ b/extras/shell/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java
@@ -128,6 +128,25 @@
}
@Test
+ public void createPCJ_noExportStrategy() throws InstanceDoesNotExistException, RyaClientException, IOException {
+ // Mock the object that performs the create operation.
+ final String instanceName = "unitTest";
+
+ final RyaClient mockCommands = mock(RyaClient.class);
+
+ final SharedShellState state = new SharedShellState();
+ state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockCommands);
+ state.connectedToInstance(instanceName);
+
+ // Execute the command.
+ final RyaAdminCommands commands = new RyaAdminCommands(state, mock(InstallPrompt.class), mock(SparqlPrompt.class), mock(UninstallPrompt.class));
+ final String message = commands.createPcj(false, false);
+
+ // Verify a message is returned that explains what was created.
+ assertEquals("The user must specify at least one export strategy: (--exportToRya, --exportToKafka)", message);
+ }
+
+ @Test
public void deletePCJ() throws InstanceDoesNotExistException, RyaClientException {
// Mock the object that performs the delete operation.
final DeletePCJ mockDeletePCJ = mock(DeletePCJ.class);