Search in sources :

Example 1 with MapStorageReader

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;
}
Also used : MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) Mav(io.datarouter.web.handler.mav.Mav) MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) PathNode(io.datarouter.pathnode.PathNode) Node(io.datarouter.storage.node.Node) MapStorageReader(io.datarouter.storage.node.op.raw.read.MapStorageReader)

Aggregations

PathNode (io.datarouter.pathnode.PathNode)1 Node (io.datarouter.storage.node.Node)1 MapStorageReader (io.datarouter.storage.node.op.raw.read.MapStorageReader)1 Mav (io.datarouter.web.handler.mav.Mav)1 MessageMav (io.datarouter.web.handler.mav.imp.MessageMav)1