Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.net.URI;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -101,7 +102,7 @@ public Mono<ActionExecutionResult> execute(JedisPool jedisPool,
}

ActionExecutionResult actionExecutionResult = new ActionExecutionResult();
actionExecutionResult.setBody(objectMapper.valueToTree(processCommandOutput(commandOutput)));
actionExecutionResult.setBody(objectMapper.valueToTree(removeQuotes(processCommandOutput(commandOutput))));
actionExecutionResult.setIsExecutionSuccess(true);

System.out.println(Thread.currentThread().getName() + ": In the RedisPlugin, got action execution result");
Expand Down Expand Up @@ -138,6 +139,32 @@ public Mono<ActionExecutionResult> execute(JedisPool jedisPool,
.subscribeOn(scheduler);
}

/**
* - This method removes the outermost quotes - single or double quotes - so that end users don't have to do
* it via javascript on the UI editor.
* - Some example inputs and outputs:
* o "my val" -> my val
* o 'my val' -> my val
* o '{"key": "val"}' -> {"key": "val"}
*/
private Object removeQuotes(Object result) {
if (result instanceof String) {
return ((String) result).replaceAll("^\\\"|^'|\\\"$|'$", "");
}
else if (result instanceof Collection) {
return ((Collection) result).stream()
.map(this::removeQuotes)
.collect(Collectors.toList());
}
else if (result instanceof Map) {
return ((Map<String, Object>) result).entrySet().stream()
.map(item -> Map.entry(item.getKey(), removeQuotes(item.getValue())))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

return result;
}

private Map getCommandAndArgs(String query) {
/**
* - This regex matches either a whole word, or anything inside double quotes. If something is inside
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ public void itShouldExecuteCommandWithArgs() {
Assert.assertNotNull(actionExecutionResult.getBody());
final JsonNode node = ((ArrayNode) actionExecutionResult.getBody());
Assert.assertEquals("value", node.get(0).get("result").asText());
Assert.assertEquals("\"value\"", node.get(1).get("result").asText());
Assert.assertEquals("\"my value\"", node.get(2).get("result").asText());
Assert.assertEquals("'value'", node.get(3).get("result").asText());
Assert.assertEquals("'my value'", node.get(4).get("result").asText());
Assert.assertEquals("'{\"a\":\"b\"}'", node.get(5).get("result").asText());
Assert.assertEquals("value", node.get(1).get("result").asText());
Assert.assertEquals("my value", node.get(2).get("result").asText());
Assert.assertEquals("value", node.get(3).get("result").asText());
Assert.assertEquals("my value", node.get(4).get("result").asText());
Assert.assertEquals("{\"a\":\"b\"}", node.get(5).get("result").asText());
}).verifyComplete();
}

Expand Down