Class OpenLineageClientUtils


  • public final class OpenLineageClientUtils
    extends java.lang.Object
    Utility class for OpenLineageClient that provides common functionalities for object mapping, JSON and YAML parsing, and URI manipulation.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void configureObjectMapper​(java.lang.String... disableFacets)
      Configures the object mapper to exclude specified facets from being serialized.
      static <T> T convertValue​(java.lang.Object fromValue, java.lang.Class<T> toValueType)
      Converts the value of an object from one type to another.
      static <T> T fromJson​(@NonNull java.lang.String json, @NonNull com.fasterxml.jackson.core.type.TypeReference<T> type)
      Converts the provided JSON string to an instance of the specified type.
      static <T extends OpenLineageConfig>
      T
      loadOpenLineageConfigJson​(java.io.InputStream inputStream, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef)
      Loads and parses OpenLineage JSON configuration from an InputStream.
      static <T extends OpenLineageConfig>
      T
      loadOpenLineageConfigYaml​(ConfigPathProvider configPathProvider, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef)
      Loads and parses OpenLineage configuration from the provided paths.
      static <T extends OpenLineageConfig>
      T
      loadOpenLineageConfigYaml​(java.io.InputStream inputStream, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef)
      Loads and parses OpenLineage YAML configuration from an InputStream.
      static <T,​F>
      T
      mergeFacets​(java.util.Map<java.lang.String,​F> facetsMap, T facetsContainer, java.lang.Class<T> klass)
      Merges the given facets map with an existing facets container, giving precedence to the values in the facets map.
      static com.fasterxml.jackson.databind.ObjectMapper newObjectMapper()
      Creates a new ObjectMapper instance configured with modules for JDK8 and JavaTime, including settings to ignore unknown properties and to not write dates as timestamps.
      static com.fasterxml.jackson.databind.ObjectMapper newObjectMapper​(com.fasterxml.jackson.core.JsonFactory jsonFactory)
      Creates a new ObjectMapper instance configured with modules for JDK8 and JavaTime, including settings to ignore unknown properties and to not write dates as timestamps.
      static OpenLineage.RunEvent runEventFromJson​(@NonNull java.lang.String json)
      Convenience method to convert a JSON string directly into a OpenLineage.RunEvent instance.
      static java.lang.String toJson​(@NonNull java.lang.Object value)
      Converts the provided value to a JSON string.
      static java.net.URI toUri​(@NonNull java.lang.String urlString)
      Converts a string URL into an URI object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • newObjectMapper

        public static com.fasterxml.jackson.databind.ObjectMapper newObjectMapper()
        Creates a new ObjectMapper instance configured with modules for JDK8 and JavaTime, including settings to ignore unknown properties and to not write dates as timestamps.
        Returns:
        A configured ObjectMapper instance.
      • newObjectMapper

        public static com.fasterxml.jackson.databind.ObjectMapper newObjectMapper​(com.fasterxml.jackson.core.JsonFactory jsonFactory)
        Creates a new ObjectMapper instance configured with modules for JDK8 and JavaTime, including settings to ignore unknown properties and to not write dates as timestamps.
        Parameters:
        jsonFactory - JsonFactory
        Returns:
        A configured ObjectMapper instance.
      • configureObjectMapper

        public static void configureObjectMapper​(java.lang.String... disableFacets)
        Configures the object mapper to exclude specified facets from being serialized.
        Parameters:
        disableFacets - Array of facet names to be excluded from serialization.
      • toJson

        public static java.lang.String toJson​(@NonNull
                                              @NonNull java.lang.Object value)
                                       throws java.io.UncheckedIOException
        Converts the provided value to a JSON string.
        Parameters:
        value - The object to be converted to JSON.
        Returns:
        A JSON string representation of the object.
        Throws:
        java.io.UncheckedIOException - If an I/O error occurs during conversion.
      • fromJson

        public static <T> T fromJson​(@NonNull
                                     @NonNull java.lang.String json,
                                     @NonNull
                                     @NonNull com.fasterxml.jackson.core.type.TypeReference<T> type)
                              throws java.io.UncheckedIOException
        Converts the provided JSON string to an instance of the specified type.
        Type Parameters:
        T - The generic type of the return value.
        Parameters:
        json - The JSON string to be converted.
        type - The type to convert the JSON string into.
        Returns:
        An instance of the specified type.
        Throws:
        java.io.UncheckedIOException - If an I/O error occurs during conversion.
      • runEventFromJson

        public static OpenLineage.RunEvent runEventFromJson​(@NonNull
                                                            @NonNull java.lang.String json)
                                                     throws java.io.UncheckedIOException
        Convenience method to convert a JSON string directly into a OpenLineage.RunEvent instance.
        Parameters:
        json - The JSON string representing a OpenLineage.RunEvent.
        Returns:
        An instance of OpenLineage.RunEvent.
        Throws:
        java.io.UncheckedIOException - If an I/O error occurs during conversion.
      • convertValue

        public static <T> T convertValue​(java.lang.Object fromValue,
                                         java.lang.Class<T> toValueType)
        Converts the value of an object from one type to another.
        Type Parameters:
        T - The generic type of the target type.
        Parameters:
        fromValue - The object whose value is to be converted.
        toValueType - The target type for the conversion.
        Returns:
        An object of the target type with the value converted from the original object.
      • mergeFacets

        public static <T,​F> T mergeFacets​(java.util.Map<java.lang.String,​F> facetsMap,
                                                T facetsContainer,
                                                java.lang.Class<T> klass)
        Merges the given facets map with an existing facets container, giving precedence to the values in the facets map.
        Type Parameters:
        T - The type of the facets container.
        F - The type of facets in the map.
        Parameters:
        facetsMap - A map containing facets to be merged.
        facetsContainer - The existing container of facets.
        klass - The class of the facets container.
        Returns:
        A new instance of the facets container with merged values.
      • toUri

        public static java.net.URI toUri​(@NonNull
                                         @NonNull java.lang.String urlString)
                                  throws OpenLineageClientException
        Converts a string URL into an URI object.
        Parameters:
        urlString - The string URL to be converted.
        Returns:
        An URI object.
        Throws:
        OpenLineageClientException - If the given string does not conform to the URI specification.
      • loadOpenLineageConfigYaml

        public static <T extends OpenLineageConfig> T loadOpenLineageConfigYaml​(ConfigPathProvider configPathProvider,
                                                                                com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef)
                                                                         throws OpenLineageClientException
        Loads and parses OpenLineage configuration from the provided paths. Throws an OpenLineageClientException if one of the following conditions are met:
        1. The provided configPathProvider is null
        2. No configuration file could be found at any of the provided paths
        3. Load the default configuration from the classpath if no file is found
        Type Parameters:
        T - generic type of merged config
        Parameters:
        configPathProvider - Provides the paths where the configuration files can be found.
        valueTypeRef - The type to convert the JSON string into.
        Returns:
        An instance of OpenLineageConfig containing the parsed configuration.
        Throws:
        OpenLineageClientException - According to the rules defined above.
      • loadOpenLineageConfigYaml

        public static <T extends OpenLineageConfig> T loadOpenLineageConfigYaml​(java.io.InputStream inputStream,
                                                                                com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef)
                                                                         throws OpenLineageClientException
        Loads and parses OpenLineage YAML configuration from an InputStream.
        Type Parameters:
        T - generic type of merged config
        Parameters:
        inputStream - The InputStream from which to load the configuration.
        valueTypeRef - The type to convert the JSON string into.
        Returns:
        An instance of OpenLineageConfig containing the parsed YAML configuration.
        Throws:
        OpenLineageClientException - If an error occurs while reading or parsing the configuration.
      • loadOpenLineageConfigJson

        public static <T extends OpenLineageConfig> T loadOpenLineageConfigJson​(java.io.InputStream inputStream,
                                                                                com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef)
                                                                         throws OpenLineageClientException
        Loads and parses OpenLineage JSON configuration from an InputStream.
        Type Parameters:
        T - generic type of merged config
        Parameters:
        inputStream - The InputStream from which to load the configuration.
        valueTypeRef - The type to convert the JSON string into.
        Returns:
        An instance of OpenLineageConfig containing the parsed JSON configuration.
        Throws:
        OpenLineageClientException - If an error occurs while reading or parsing the configuration.