use of io.datarouter.storage.node.op.raw.read.MapStorageReader in project datarouter by hotpads.
the class GetNodeDataHandler method get.
@Handler
private <PK extends PrimaryKey<PK>, D extends Databean<PK, D>> Mav get(String nodeName) {
Mav mav = showForm();
@SuppressWarnings("unchecked") Node<PK, ?, ?> node = (Node<PK, ?, ?>) nodes.getNode(nodeName);
limit = mav.put(PARAM_limit, params.optionalInteger(PARAM_limit).orElse(100));
List<String> fieldValues = getFieldValues(node);
String encodedPk = PercentFieldCodec.encode(fieldValues.stream());
PK primaryKey = PrimaryKeyPercentCodecTool.decode(node.getFieldInfo().getPrimaryKeySupplier(), encodedPk);
@SuppressWarnings("unchecked") MapStorageReader<PK, D> mapStorageNode = (MapStorageReader<PK, D>) node;
if (!mapStorageNode.exists(primaryKey)) {
return new MessageMav("databean does not exist");
}
D mapDatabean = mapStorageNode.get(primaryKey);
List<D> databeans = Scanner.ofNullable(mapDatabean).list();
addDatabeansToMav(mav, databeans);
logger.warn("Retrieved databean {}", encodedPk);
return mav;
}
Aggregations