Interface ReportNode

All Known Implementing Classes:
ReportNodeImpl, ReportNodeNoOp

public interface ReportNode
A ReportNode allows building up functional reports with a tree hierarchy.

Each ReportNode is defined by

  • a map of TypedValue indexed by their keys,
  • a default String message template containing the functional message in the default language, which may contain references to those values or to the values of one of its ancestors,
  • a String message key identifying the unique corresponding functional report template; this key is used in particular to build a dictionary of all the message templates,
  • a collection of ReportNode children, possibly empty.
The values TypedValue values should be referred to by their key in the message template, using the ${key} syntax, in order to be later replaced by StringSubstitutor for instance when formatting the string for the end user. The ReportNode values may be referred to within the corresponding messageTemplate, or within any of its descendants. Be aware that any descendant might override a value by giving a new value to an existing key. All implementations of ReportNode need to take that inheritance into account.

Instances of ReportNode are not thread-safe. When a new thread is created, a new ReportNode should be provided to the process in that thread. A ReportNode is not meant to be shared with other threads. Therefore, it should rather not be saved as a class parameter of an object which could be used by separate threads. In those cases it should instead be passed on in methods through their arguments.

The ReportNode is designed for multilingual support. Indeed, each ReportNode message can be translated based on their key and using the value keys in the desired order.

Author:
Florian Dupuy <florian.dupuy at rte-france.com>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ReportNode
    A No-op implementation of ReportNode
  • Method Summary

    Modifier and Type
    Method
    Description
    Get the children of current node
    Get the message of current node, replacing ${key} references in the message template with the corresponding values, either contained in current node or in one of its parents.
    Get the message key for current node.
    Get the message template for current node.
    getValue(String valueKey)
    Get the value corresponding to the given key
    Get the values which belong to current node (does not include the inherited values)
    void
    include(ReportNode reportRoot)
    Add a ReportNode as a child of current ReportNode.
    Create a new adder to create a ReportNode child.
    Create a new builder for creating a root ReportNode.
    void
    print(Writer writer)
    Print to given writer the current report node and its descendants
    default void
    print(Path path)
    Print to given path the current report node and its descendants
    void
    writeJson(com.fasterxml.jackson.core.JsonGenerator generator)
    Serialize the current report node
  • Field Details

    • NO_OP

      static final ReportNode NO_OP
      A No-op implementation of ReportNode
  • Method Details

    • newRootReportNode

      static ReportNodeBuilder newRootReportNode()
      Create a new builder for creating a root ReportNode.
      Returns:
      a ReportNodeBuilder
    • getMessageKey

      String getMessageKey()
      Get the message key for current node. Note that each key needs to correspond to a unique message template. This allows to build up a dictionary of message templates indexed by their key.
      Returns:
      the key
    • getMessageTemplate

      String getMessageTemplate()
      Get the message template for current node.
      Returns:
      the message template
    • getMessage

      String getMessage()
      Get the message of current node, replacing ${key} references in the message template with the corresponding values, either contained in current node or in one of its parents.
      Returns:
      the message
    • getValues

      Map<String,TypedValue> getValues()
      Get the values which belong to current node (does not include the inherited values)
      Returns:
      the values unmodifiable map
    • getValue

      Optional<TypedValue> getValue(String valueKey)
      Get the value corresponding to the given key
      Parameters:
      valueKey - the key to request
      Returns:
      the value
    • getChildren

      List<ReportNode> getChildren()
      Get the children of current node
      Returns:
      the children nodes
    • newReportNode

      ReportNodeAdder newReportNode()
      Create a new adder to create a ReportNode child.
      Returns:
      the created ReportNodeAdder
    • include

      void include(ReportNode reportRoot)
      Add a ReportNode as a child of current ReportNode.
      Parameters:
      reportRoot - the ReportNode to add, it needs to be a root ReportNode
    • writeJson

      void writeJson(com.fasterxml.jackson.core.JsonGenerator generator) throws IOException
      Serialize the current report node
      Parameters:
      generator - the jsonGenerator to use for serialization
      Throws:
      IOException
    • print

      default void print(Path path) throws IOException
      Print to given path the current report node and its descendants
      Parameters:
      path - the writer to write to
      Throws:
      IOException
    • print

      void print(Writer writer) throws IOException
      Print to given writer the current report node and its descendants
      Parameters:
      writer - the writer to write to
      Throws:
      IOException