Browse Source

feat(attributes): CoAP allClientKeys/allSharedKeys query params

Additive per-scope fetch-all; existing clientKeys/sharedKeys and onlyShared unchanged.
pull/15865/head
dshvaika 3 months ago
parent
commit
7d0b54a75e
  1. 20
      common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/adaptors/CoapAdaptorUtils.java

20
common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/adaptors/CoapAdaptorUtils.java

@ -31,12 +31,18 @@ public class CoapAdaptorUtils {
List<String> queryElements = inbound.getOptions().getUriQuery(); List<String> queryElements = inbound.getOptions().getUriQuery();
TransportProtos.GetAttributeRequestMsg.Builder result = TransportProtos.GetAttributeRequestMsg.newBuilder(); TransportProtos.GetAttributeRequestMsg.Builder result = TransportProtos.GetAttributeRequestMsg.newBuilder();
if (queryElements != null && queryElements.size() > 0) { if (queryElements != null && queryElements.size() > 0) {
boolean allClient = "true".equalsIgnoreCase(getQueryValue(queryElements, "allClientKeys"));
boolean allShared = "true".equalsIgnoreCase(getQueryValue(queryElements, "allSharedKeys"));
Set<String> clientKeys = toKeys(queryElements, "clientKeys"); Set<String> clientKeys = toKeys(queryElements, "clientKeys");
Set<String> sharedKeys = toKeys(queryElements, "sharedKeys"); Set<String> sharedKeys = toKeys(queryElements, "sharedKeys");
if (clientKeys != null) { if (allClient) {
result.setAllClientAttributes(true);
} else if (clientKeys != null) {
result.addAllClientAttributeNames(clientKeys); result.addAllClientAttributeNames(clientKeys);
} }
if (sharedKeys != null) { if (allShared) {
result.setAllSharedAttributes(true);
} else if (sharedKeys != null) {
result.addAllSharedAttributeNames(sharedKeys); result.addAllSharedAttributeNames(sharedKeys);
} }
} }
@ -44,6 +50,16 @@ public class CoapAdaptorUtils {
return result.build(); return result.build();
} }
private static String getQueryValue(List<String> queryElements, String name) {
for (String queryElement : queryElements) {
String[] queryItem = queryElement.split("=");
if (queryItem.length == 2 && queryItem[0].equals(name)) {
return queryItem[1];
}
}
return null;
}
private static Set<String> toKeys(List<String> queryElements, String attributeName) throws AdaptorException { private static Set<String> toKeys(List<String> queryElements, String attributeName) throws AdaptorException {
String keys = null; String keys = null;
for (String queryElement : queryElements) { for (String queryElement : queryElements) {

Loading…
Cancel
Save