1 package org
.asamk
.signal
.commands
;
3 import com
.fasterxml
.jackson
.core
.type
.TypeReference
;
5 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
7 import org
.asamk
.signal
.OutputType
;
8 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
9 import org
.asamk
.signal
.manager
.Manager
;
10 import org
.asamk
.signal
.util
.Util
;
12 import java
.util
.List
;
16 public interface JsonRpcLocalCommand
extends JsonRpcCommand
<Map
<String
, Object
>> {
18 void handleCommand(Namespace ns
, Manager m
) throws CommandException
;
20 default TypeReference
<Map
<String
, Object
>> getRequestType() {
21 return new TypeReference
<>() {
25 default void handleCommand(Map
<String
, Object
> request
, Manager m
) throws CommandException
{
26 Namespace commandNamespace
= new JsonRpcNamespace(request
== null ? Map
.of() : request
);
27 handleCommand(commandNamespace
, m
);
30 default Set
<OutputType
> getSupportedOutputTypes() {
31 return Set
.of(OutputType
.PLAIN_TEXT
, OutputType
.JSON
);
35 * Namepace implementation, that defaults booleans to false and converts camel case keys to dashed strings
37 final class JsonRpcNamespace
extends Namespace
{
39 public JsonRpcNamespace(final Map
<String
, Object
> attrs
) {
43 public <T
> T
get(String dest
) {
44 final T value
= super.get(dest
);
49 final var camelCaseString
= Util
.dashSeparatedToCamelCaseString(dest
);
50 return super.get(camelCaseString
);
54 public <E
> List
<E
> getList(final String dest
) {
55 final List
<E
> value
= super.getList(dest
);
60 return super.getList(dest
+ "s");
64 public Boolean
getBoolean(String dest
) {
65 Boolean maybeGotten
= this.get(dest
);
66 if (maybeGotten
== null) {