Class PersistenceJsonParser


  • public final class PersistenceJsonParser
    extends java.lang.Object
    Define a JSON format for the RDD keys used by the spark job. This class provides methods for constructing the key as well as parsing data out of the key. The JSON format should follow this structure:
     {
        "country": "USA-0-generated",
        "shard": "1-2-3",
        "metadata": {
             "scheme": "zz/",
        }
     }
     
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String createJsonKey​(java.lang.String country, java.lang.String shard, java.lang.String scheme)
      Create a JSON key with a given country and shard.
      static java.lang.String createJsonKey​(java.lang.String country, java.lang.String shard, java.util.Map<java.lang.String,​java.lang.String> metadata)
      Create a JSON key with a given country and shard.
      static java.lang.String parseCountry​(java.lang.String json)
      Given a valid JSON key, parse and return the value of the "country" property.
      static java.util.Map<java.lang.String,​java.lang.String> parseMetadata​(java.lang.String json)
      Given a valid JSON key, parse and return the "metadata" property as a string to string Map.
      static java.util.Optional<java.lang.String> parseScheme​(java.lang.String json)
      Given a valid JSON key, parse and return the value of the "scheme" property within the "metadata" object, if present.
      static java.lang.String parseShard​(java.lang.String json)
      Given a valid JSON key, parse and return the value of the "shard" property.
      • Methods inherited from class java.lang.Object

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

      • createJsonKey

        public static java.lang.String createJsonKey​(java.lang.String country,
                                                     java.lang.String shard,
                                                     java.lang.String scheme)
        Create a JSON key with a given country and shard. Automatically populate a metadata object with some given scheme information.
        Parameters:
        country - the country, usually the ISO3 country code as well as possible creative additions
        shard - the shard name, i.e. the result of Shard.getName()
        scheme - the scheme string, e.g. zz/
        Returns:
        a JSON key with the given elements
      • createJsonKey

        public static java.lang.String createJsonKey​(java.lang.String country,
                                                     java.lang.String shard,
                                                     java.util.Map<java.lang.String,​java.lang.String> metadata)
        Create a JSON key with a given country and shard. Also, provide a string to string Map containing the desired metadata.
        Parameters:
        country - the country, usually the ISO3 country code as well as possible creative additions
        shard - the shard name, i.e. the result of Shard.getName()
        metadata - a string to string Map containing the metadata
        Returns:
        a JSON key with the given elements
      • parseCountry

        public static java.lang.String parseCountry​(java.lang.String json)
        Given a valid JSON key, parse and return the value of the "country" property.
        Parameters:
        json - the JSON key
        Returns:
        the value of the country property
      • parseMetadata

        public static java.util.Map<java.lang.String,​java.lang.String> parseMetadata​(java.lang.String json)
        Given a valid JSON key, parse and return the "metadata" property as a string to string Map.
        Parameters:
        json - the JSON key
        Returns:
        the value of the metadata property
      • parseScheme

        public static java.util.Optional<java.lang.String> parseScheme​(java.lang.String json)
        Given a valid JSON key, parse and return the value of the "scheme" property within the "metadata" object, if present. Otherwise, return an empty Optional.
        Parameters:
        json - the JSON key
        Returns:
        the value of the scheme property if present, otherwise an empty Optional
      • parseShard

        public static java.lang.String parseShard​(java.lang.String json)
        Given a valid JSON key, parse and return the value of the "shard" property.
        Parameters:
        json - the JSON key
        Returns:
        the value of the shard property