Class DcatDocumentFormatter

java.lang.Object
org.odpi.openmetadata.frameworks.integration.dcat.DcatDocumentFormatter

public class DcatDocumentFormatter extends Object
DcatDocumentFormatter reads and writes DCAT documents. The documents are in JSON-LD format, which is the serialization of DCAT that is also valid JSON. Any arrangement of a JSON-LD document can be read (nested, flattened, with prefixes or with full IRIs). Documents written by this class embed their context and nest the description of a dataset's distributions, publisher and contact points inside the dataset. 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

    • parseDocument

      public static DcatDocument parseDocument(String rawDocument) throws IOException
      Parse a DCAT document.
      Parameters:
      rawDocument - document in JSON-LD format
      Returns:
      bean version of the document
      Throws:
      IOException - the document is not valid JSON-LD
    • hasContent

      public static boolean hasContent(DcatDocument document)
      Return whether a document describes at least one catalog, dataset or data service.
      Parameters:
      document - bean version of the document
      Returns:
      boolean
    • toJSONLDStructure

      public static Map<String,Object> toJSONLDStructure(DcatDocument document)
      Convert a DCAT document into the structure of a JSON-LD document. This structure can be embedded in another JSON document, such as the response to a REST API call.
      Parameters:
      document - bean version of the document
      Returns:
      map that serializes to the JSON-LD document
    • toJSONLD

      public static String toJSONLD(DcatDocument document) throws IOException
      Write a DCAT document as JSON-LD.
      Parameters:
      document - bean version of the document
      Returns:
      JSON-LD string
      Throws:
      IOException - problem serializing the document
    • toJSONFragment

      public static String toJSONFragment(Object bean) throws IOException
      Write any DCAT bean (or list of beans) as plain JSON. This is used to keep fragments of a document, such as the details of its publisher, 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 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 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
    • fromJSONFragmentMapOfLists

      public static Map<String,List<String>> fromJSONFragmentMapOfLists(String json) throws IOException
      Read a map of lists of strings from a JSON fragment written by toJSONFragment.
      Parameters:
      json - JSON string (may be null)
      Returns:
      map or null if the fragment is absent
      Throws:
      IOException - problem parsing the JSON
    • fromJSONFragmentMap

      public static Map<String,String> fromJSONFragmentMap(String json) throws IOException
      Read a map of strings from a JSON fragment written by toJSONFragment.
      Parameters:
      json - JSON string (may be null)
      Returns:
      map or null if the fragment is absent
      Throws:
      IOException - problem parsing the JSON