Class BitolDocumentFormatter

java.lang.Object
org.odpi.openmetadata.frameworks.integration.bitol.BitolDocumentFormatter

public class BitolDocumentFormatter extends Object
BitolDocumentFormatter converts Bitol documents between their serialized form (YAML or JSON) and the Egeria beans. The Bitol standards use YAML as their primary encoding but JSON is also valid; since JSON is a subset of YAML, a single YAML-based reader handles both. Documents written by this class are YAML. The class is stateless and its methods are thread-safe. Parsing problems are reported as IOException so that callers do not need the Jackson libraries on their classpath.
  • Method Details

    • newYAMLMapper

      public static com.fasterxml.jackson.databind.ObjectMapper newYAMLMapper()
      Create a Jackson ObjectMapper that reads and writes Bitol documents in YAML. It also reads JSON. A new mapper is returned each time so that the caller can configure it further.
      Returns:
      configured mapper
    • newJSONMapper

      public static com.fasterxml.jackson.databind.ObjectMapper newJSONMapper()
      Create a Jackson ObjectMapper that reads and writes Bitol documents in JSON. A new mapper is returned each time so that the caller can configure it further.
      Returns:
      configured mapper
    • getKind

      public static String getKind(String rawDocument) throws IOException
      Return the value of the "kind" property of a document without mapping the whole document to a bean. This is useful for routing a document whose full content cannot be parsed.
      Parameters:
      rawDocument - document in YAML or JSON format
      Returns:
      the kind (typically DataContract or DataProduct) or null if the document has no kind property
      Throws:
      IOException - the document is not valid YAML/JSON
    • parseDocument

      public static BitolDocument parseDocument(String rawDocument) throws IOException
      Parse a Bitol document of either kind. The subclass is selected from the document's "kind" property.
      Parameters:
      rawDocument - document in YAML or JSON format
      Returns:
      DataContract or DataProduct bean
      Throws:
      IOException - the document is not valid or has an unrecognized kind
    • parseDataContract

      public static DataContract parseDataContract(String rawDocument) throws IOException
      Parse an Open Data Contract Standard (ODCS) data contract.
      Parameters:
      rawDocument - document in YAML or JSON format
      Returns:
      DataContract bean
      Throws:
      IOException - the document is not valid or is not a data contract
    • parseDataProduct

      public static DataProduct parseDataProduct(String rawDocument) throws IOException
      Parse an Open Data Product Standard (ODPS) data product.
      Parameters:
      rawDocument - document in YAML or JSON format
      Returns:
      DataProduct bean
      Throws:
      IOException - the document is not valid or is not a data product
    • toYAML

      public static String toYAML(BitolDocument document) throws IOException
      Write a Bitol document as YAML (the standards' primary encoding).
      Parameters:
      document - DataContract or DataProduct bean
      Returns:
      YAML string
      Throws:
      IOException - problem serializing the bean
    • toJSONFragment

      public static String toJSONFragment(Object bean) throws IOException
      Write any Bitol bean (or list of beans) as JSON. This is used to keep fragments of a document, such as its SLA properties, losslessly in the additional properties of an open metadata element.
      Parameters:
      bean - bean or list of beans
      Returns:
      JSON string
      Throws:
      IOException - problem serializing the bean
    • fromJSONFragment

      public static <T> T fromJSONFragment(String json, Class<T> beanClass) throws IOException
      Read a single Bitol bean from a JSON fragment written by toJSONFragment.
      Type Parameters:
      T - bean type
      Parameters:
      json - JSON string (may be null)
      beanClass - class of the bean
      Returns:
      bean or null if the fragment is absent
      Throws:
      IOException - problem parsing the JSON
    • fromJSONFragmentList

      public static <T> List<T> fromJSONFragmentList(String json, Class<T> beanClass) throws IOException
      Read a list of Bitol beans from a JSON fragment written by toJSONFragment.
      Type Parameters:
      T - bean type
      Parameters:
      json - JSON string (may be null)
      beanClass - class of the list elements
      Returns:
      list of beans or null if the fragment is absent
      Throws:
      IOException - problem parsing the JSON
    • toJSON

      public static String toJSON(BitolDocument document) throws IOException
      Write a Bitol document as JSON.
      Parameters:
      document - DataContract or DataProduct bean
      Returns:
      JSON string
      Throws:
      IOException - problem serializing the bean